From f1389bcfef76503d1e90380cc6ea85c4e2b42baa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 12:25:08 +0000 Subject: [PATCH 001/108] Auto-generated commit e618c2c3d1e5c1df4d76b5e5175a7ab72c349374 --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 293 ++++++ index.d.ts | 74 ++ index.mjs | 4 + index.mjs.map | 1 + package.json | 39 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 3610 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..8aa6664 --- /dev/null +++ b/README.md @@ -0,0 +1,293 @@ + + +# sub2ind + +[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] + +> Convert subscripts to a linear index. + + + +
+ +
+ + + + + + + +
+ +## Usage + +```javascript +import sub2ind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-sub2ind@esm/index.mjs'; +``` + +#### sub2ind( shape, ...subscripts\[, options] ) + +Converts subscripts to a linear index. + +```javascript +var shape = [ 2, 2 ]; + +var idx = sub2ind( shape, 1, 0 ); +// returns 2 +``` + +The function supports the following `options`: + +- `mode`: specifies how to handle subscripts which exceed array dimensions. The following modes are supported: + + - `throw`: specifies that the function should throw an error when a subscript exceeds array dimensions. + - `wrap`: specifies that the function should wrap around subscripts exceeding array dimensions using modulo arithmetic. + - `clamp`: specifies that the function should set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. + + If provided a `mode` array, each array element corresponds to a dimension. If provided fewer modes than dimensions, the function reuses modes using modulo arithmetic. Default: `[ 'throw' ]`. + +- `order`: specifies whether an array is `row-major` (C-style) or `column-major` (Fortran-style). Default: `'row-major'`. + +By default, the function assumes a row-major array. To return a linear index for a column-major array, set the `order` option. + +```javascript +var shape = [ 2, 2 ]; +var opts = {}; + +opts.order = 'column-major'; +var idx = sub2ind( shape, 1, 0, opts ); +// returns 1 +``` + +By default, the function throws an `error` if provided subscripts which exceed array dimensions. To specify alternative behavior, set the `mode` option. + +```javascript +var shape = [ 2, 2 ]; +var opts = {}; + +opts.mode = 'wrap'; +var idx = sub2ind( shape, -2, 0, opts ); +// returns 0 + +opts.mode = 'clamp'; +idx = sub2ind( shape, 10, 10, opts ); +// returns 3 +``` + +To specify separate modes for each dimension, provide a `mode` array. + +```javascript +var shape = [ 2, 2, 2 ]; +var opts = { + 'mode': [ + 'wrap', + 'clamp' + ] +}; + +var idx = sub2ind( shape, -2, 10, -1, opts ); +// returns 3 +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## 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..1e2f2d8 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,74 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2021 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT 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 { Order } from '@stdlib/types/ndarray'; + +/** +* Interface defining function options. +*/ +interface Options { + /** + * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). + */ + mode?: Array; + + /** + * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). + */ + order?: Order; +} + +/** +* Converts subscripts to a linear index. +* +* ## Notes +* +* - The function accepts the following "modes": +* +* - `throw`: throws an error when a subscript exceeds array dimensions. +* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. +* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. +* +* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. +* +* +* @param shape - array shape +* @param args - subscripts followed by an optional options object +* @throws first argument must be an array-like object containing nonnegative integers +* @throws subscripts must be integer valued +* @throws must provide valid options +* @throws must provide subscripts which do not exceed array dimensions +* @throws number of subscripts much match the number of dimensions +* @returns linear index +* +* @example +* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); +* // returns 17 +*/ +declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length + + +// EXPORTS // + +export = sub2ind; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..aefa8bf --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var p={mode:["throw"],order:"row-major"},l=n,u=o,j=d,h=m,g=a,b=i;var f=function(e,r){var s;if(!l(r))return new TypeError(b("invalid argument. Options argument must be an object. Value: `%s`.",r));if(u(r,"mode")){if(e.mode=r.mode,j(e.mode)){if(0===e.mode.length)return new TypeError(b("invalid option. `%s` option cannot be an empty array.","mode"))}else e.mode=[e.mode];for(s=0;sr+1){if(i=T(t,arguments[d=n-1]))throw i}else d=n;if(d-(o=1)!==r)throw new RangeError(x("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: %u. Number of subscripts: %u.",r,d-o));for((s=new Array(r+4))[0]=e,s[1]=y(e,t.order),s[2]=0;o ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: %u. Number of subscripts: %u.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: %u. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"],"names":["isObject","require$$0","hasOwnProp","require$$1","isArray","require$$2","isOrder","require$$3","isIndexMode","require$$4","format","require$$5","validate_1","opts","options","i","TypeError","mode","length","order","isNonNegativeIntegerArray","primitives","isInteger","isPrimitive","shape2strides","getIndex","defaults","validate","require$$6","lib","shape","ndims","args","err","len","j","arguments","slice","RangeError","Array","apply"],"mappings":";;y7BAsBIA,EAAWC,EACXC,EAAaC,EACbC,EAAUC,EACVC,EAAUC,EACVC,EAAcC,EACdC,EAASC,EAwDb,IAAAC,EA9BA,SAAmBC,EAAMC,GACxB,IAAIC,EACJ,IAAMf,EAAUc,GACf,OAAO,IAAIE,UAAWN,EAAQ,qEAAsEI,IAErG,GAAKZ,EAAYY,EAAS,QAAW,CAEpC,GADAD,EAAKI,KAAOH,EAAQG,KACdb,EAASS,EAAKI,OAEb,GAA0B,IAArBJ,EAAKI,KAAKC,OACrB,OAAO,IAAIF,UAAWN,EAAQ,wDAAyD,cAFvFG,EAAKI,KAAO,CAAEJ,EAAKI,MAIpB,IAAMF,EAAI,EAAGA,EAAIF,EAAKI,KAAKC,OAAQH,IAClC,IAAMP,EAAaK,EAAKI,KAAMF,IAC7B,OAAO,IAAIC,UAAWN,EAAQ,iFAAkF,OAAQG,EAAKI,KAAMF,KAItI,OAAKb,EAAYY,EAAS,WACzBD,EAAKM,MAAQL,EAAQK,OACfb,EAASO,EAAKM,QACZ,IAAIH,UAAWN,EAAQ,kFAAmF,QAASG,EAAKM,QAG1H,MCvDJC,EAA4BnB,EAAyDoB,WACrFC,EAAYnB,EAAuCoB,YACnDC,EAAgBnB,EAChBoB,EAAWlB,EACXG,EAASD,EACTiB,EAAWf,EACXgB,EAAWC,EAyFf,IC9EAC,EDyBA,WACC,IACIC,EACAC,EACAC,EACAnB,EACAoB,EACAC,EACAnB,EACAoB,EAGJ,IAAMf,EADNU,EAAQM,UAAW,IAElB,MAAM,IAAIpB,UAAWN,EAAQ,8GAA+GoB,IAS7I,GAPAI,EAAME,UAAUlB,OAChBa,EAAQD,EAAMZ,QAEdL,EAAO,IACFI,KAAOS,EAAST,KAAKoB,QAC1BxB,EAAKM,MAAQO,EAASP,MAEjBe,EAAMH,EAAM,GAIhB,GADAE,EAAMN,EAAUd,EADNuB,UADVD,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLpB,EAAI,KACSgB,EACZ,MAAM,IAAIO,WAAY5B,EAAQ,4HAA6HqB,EAAOI,EAAEpB,IAMrK,KAJAiB,EAAO,IAAIO,MAAOR,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMR,EAAeM,EAAOjB,EAAKM,OACvCa,EAAM,GAAM,EACJjB,EAAIoB,EAAGpB,IAAM,CACpB,IAAMO,EAAWc,UAAWrB,IAC3B,MAAM,IAAIC,UAAWN,EAAQ,kFAAmFK,EAAGqB,UAAWrB,KAE/HiB,EAAMjB,EAAE,GAAMqB,UAAWrB,GAG1B,OADAiB,EAAMjB,EAAE,GAAMF,EAAKI,KACZQ,EAASe,MAAO,KAAMR"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..712cfb0 --- /dev/null +++ b/package.json @@ -0,0 +1,39 @@ +{ + "name": "@stdlib/ndarray-sub2ind", + "version": "0.0.0", + "description": "Convert subscripts to a linear index.", + "license": "Apache-2.0", + "type": "module", + "main": "./index.mjs", + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/ndarray-sub2ind.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "keywords": [ + "stdlib", + "stdtypes", + "types", + "ndarray", + "shape", + "multidimensional", + "array", + "utilities", + "utility", + "utils", + "util", + "sub2ind", + "subscript", + "linear", + "index", + "idx", + "strided" + ], + "funding": { + "type": "patreon", + "url": "https://www.patreon.com/athan" + } +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..65af0ed --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From f4e7f93bedff3488b98b2671322cdf874d9f013b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 30 Jun 2022 22:05:16 +0000 Subject: [PATCH 002/108] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbdba8c..0576a9b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0N262', shape ) ); } len = arguments.length; ndims = shape.length; diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..4fa480d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0N22h', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0N265', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0N261', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 1e52109..afbe78e 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.0.x", "@stdlib/ndarray-base-shape2strides": "^0.0.x", "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From d26a2160bc3aabe280117dd771e272e13f259bfa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 09:04:21 +0000 Subject: [PATCH 003/108] Remove files --- index.d.ts | 74 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2768 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index aefa8bf..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var p={mode:["throw"],order:"row-major"},l=n,u=o,j=d,h=m,g=a,b=i;var f=function(e,r){var s;if(!l(r))return new TypeError(b("invalid argument. Options argument must be an object. Value: `%s`.",r));if(u(r,"mode")){if(e.mode=r.mode,j(e.mode)){if(0===e.mode.length)return new TypeError(b("invalid option. `%s` option cannot be an empty array.","mode"))}else e.mode=[e.mode];for(s=0;sr+1){if(i=T(t,arguments[d=n-1]))throw i}else d=n;if(d-(o=1)!==r)throw new RangeError(x("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: %u. Number of subscripts: %u.",r,d-o));for((s=new Array(r+4))[0]=e,s[1]=y(e,t.order),s[2]=0;o ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: %u. Number of subscripts: %u.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: %u. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"],"names":["isObject","require$$0","hasOwnProp","require$$1","isArray","require$$2","isOrder","require$$3","isIndexMode","require$$4","format","require$$5","validate_1","opts","options","i","TypeError","mode","length","order","isNonNegativeIntegerArray","primitives","isInteger","isPrimitive","shape2strides","getIndex","defaults","validate","require$$6","lib","shape","ndims","args","err","len","j","arguments","slice","RangeError","Array","apply"],"mappings":";;y7BAsBIA,EAAWC,EACXC,EAAaC,EACbC,EAAUC,EACVC,EAAUC,EACVC,EAAcC,EACdC,EAASC,EAwDb,IAAAC,EA9BA,SAAmBC,EAAMC,GACxB,IAAIC,EACJ,IAAMf,EAAUc,GACf,OAAO,IAAIE,UAAWN,EAAQ,qEAAsEI,IAErG,GAAKZ,EAAYY,EAAS,QAAW,CAEpC,GADAD,EAAKI,KAAOH,EAAQG,KACdb,EAASS,EAAKI,OAEb,GAA0B,IAArBJ,EAAKI,KAAKC,OACrB,OAAO,IAAIF,UAAWN,EAAQ,wDAAyD,cAFvFG,EAAKI,KAAO,CAAEJ,EAAKI,MAIpB,IAAMF,EAAI,EAAGA,EAAIF,EAAKI,KAAKC,OAAQH,IAClC,IAAMP,EAAaK,EAAKI,KAAMF,IAC7B,OAAO,IAAIC,UAAWN,EAAQ,iFAAkF,OAAQG,EAAKI,KAAMF,KAItI,OAAKb,EAAYY,EAAS,WACzBD,EAAKM,MAAQL,EAAQK,OACfb,EAASO,EAAKM,QACZ,IAAIH,UAAWN,EAAQ,kFAAmF,QAASG,EAAKM,QAG1H,MCvDJC,EAA4BnB,EAAyDoB,WACrFC,EAAYnB,EAAuCoB,YACnDC,EAAgBnB,EAChBoB,EAAWlB,EACXG,EAASD,EACTiB,EAAWf,EACXgB,EAAWC,EAyFf,IC9EAC,EDyBA,WACC,IACIC,EACAC,EACAC,EACAnB,EACAoB,EACAC,EACAnB,EACAoB,EAGJ,IAAMf,EADNU,EAAQM,UAAW,IAElB,MAAM,IAAIpB,UAAWN,EAAQ,8GAA+GoB,IAS7I,GAPAI,EAAME,UAAUlB,OAChBa,EAAQD,EAAMZ,QAEdL,EAAO,IACFI,KAAOS,EAAST,KAAKoB,QAC1BxB,EAAKM,MAAQO,EAASP,MAEjBe,EAAMH,EAAM,GAIhB,GADAE,EAAMN,EAAUd,EADNuB,UADVD,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLpB,EAAI,KACSgB,EACZ,MAAM,IAAIO,WAAY5B,EAAQ,4HAA6HqB,EAAOI,EAAEpB,IAMrK,KAJAiB,EAAO,IAAIO,MAAOR,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMR,EAAeM,EAAOjB,EAAKM,OACvCa,EAAM,GAAM,EACJjB,EAAIoB,EAAGpB,IAAM,CACpB,IAAMO,EAAWc,UAAWrB,IAC3B,MAAM,IAAIC,UAAWN,EAAQ,kFAAmFK,EAAGqB,UAAWrB,KAE/HiB,EAAMjB,EAAE,GAAMqB,UAAWrB,GAG1B,OADAiB,EAAMjB,EAAE,GAAMF,EAAKI,KACZQ,EAASe,MAAO,KAAMR"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 65af0ed..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 1e1338a496e5a08926b3752457fd8c1a17f79f61 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 09:05:11 +0000 Subject: [PATCH 004/108] 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 | 41 +- benchmark/benchmark.js | 482 ---- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 -- benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 536 ---- test/test.validate.js | 186 -- 43 files changed, 2714 insertions(+), 4874 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 d9697bc..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T22:04:36.736Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -226,7 +219,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -288,11 +281,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 7e1d5f6..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/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index cb37286..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The function does not compile if provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The function does not compile if provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 c18fc08..1e2f2d8 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4cafd93 --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;+9BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,KAI7D,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,KCbR,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,IACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,GAG1B,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0576a9b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0N262', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4fa480d..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0N22h', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0N265', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0N261', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index afbe78e..3c07840 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer-array": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/random-base-randu": "^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", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e2bb9cd --- /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 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 7f2d4255e7d826080f5959c6cfe98ead96a9604c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 17:47:59 +0000 Subject: [PATCH 005/108] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbdba8c..0576a9b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0N262', shape ) ); } len = arguments.length; ndims = shape.length; diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..4fa480d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0N22h', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0N265', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0N261', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 1e52109..afbe78e 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.0.x", "@stdlib/ndarray-base-shape2strides": "^0.0.x", "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 9178ca9649bc685669a7d0aa9574a25edc1342d4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 02:40:25 +0000 Subject: [PATCH 006/108] Remove files --- index.d.ts | 74 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2768 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4cafd93..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;+9BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,KAI7D,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,KCbR,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,IACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,GAG1B,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e2bb9cd..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 91de9b813adaded933661b7f84a6096700d97c9c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 02:41:10 +0000 Subject: [PATCH 007/108] 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 | 41 +- benchmark/benchmark.js | 482 ---- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 -- benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 536 ---- test/test.validate.js | 186 -- 43 files changed, 2714 insertions(+), 4874 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 cda6056..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T01:09:53.989Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -226,7 +219,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -288,11 +281,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 7e1d5f6..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/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index cb37286..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The function does not compile if provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The function does not compile if provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 c18fc08..1e2f2d8 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4cafd93 --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;+9BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,KAI7D,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,KCbR,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,IACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,GAG1B,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0576a9b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0N262', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4fa480d..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0N22h', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0N265', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0N261', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index afbe78e..3c07840 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer-array": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/random-base-randu": "^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", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..83a610b --- /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 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 5e853e83c8c5fd0c3c24fc5caa94af648d9385e9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:37:25 +0000 Subject: [PATCH 008/108] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbdba8c..0576a9b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0N262', shape ) ); } len = arguments.length; ndims = shape.length; diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..4fa480d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0N22h', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0N265', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0N261', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 1e52109..afbe78e 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.0.x", "@stdlib/ndarray-base-shape2strides": "^0.0.x", "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 72c25172c6db8bb1a298a183e7a70e632ea9cebc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 19:04:31 +0000 Subject: [PATCH 009/108] Remove files --- index.d.ts | 74 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2768 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4cafd93..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;+9BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,KAI7D,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,KCbR,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,IACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,GAG1B,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 83a610b..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 78c770a010df345be1a796ea1a0b6837aae5e702 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 19:06:16 +0000 Subject: [PATCH 010/108] 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 | 41 +- benchmark/benchmark.js | 482 ---- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 -- benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 536 ---- test/test.validate.js | 186 -- 42 files changed, 2714 insertions(+), 4839 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -226,7 +219,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -288,11 +281,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 7e1d5f6..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/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index cb37286..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The function does not compile if provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The function does not compile if provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 c18fc08..1e2f2d8 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..4cafd93 --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;+9BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,KAI7D,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,KCbR,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,IACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,GAG1B,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0576a9b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0N262', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4fa480d..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0N22h', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0N265', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0N261', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index afbe78e..3c07840 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer-array": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/random-base-randu": "^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", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..741fbb0 --- /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 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 453bd8f715533156df675b8eb40c8cbd0536546d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:53:35 +0000 Subject: [PATCH 011/108] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbdba8c..0576a9b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0N262', shape ) ); } len = arguments.length; ndims = shape.length; diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..4fa480d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0N22h', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0N265', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0N261', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 1e52109..afbe78e 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.0.x", "@stdlib/ndarray-base-shape2strides": "^0.0.x", "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 0ec289260ae6ad0a99667dbf2d9ed3fc230ea86b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 14:33:15 +0000 Subject: [PATCH 012/108] Remove files --- index.d.ts | 74 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2768 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4cafd93..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;+9BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,KAI7D,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,KCbR,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,IACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,GAG1B,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 741fbb0..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 4ccc8888a21a4592c66e02e28b88656e9a14962a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 14:34:08 +0000 Subject: [PATCH 013/108] 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 | 41 +- benchmark/benchmark.js | 482 ---- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 -- benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 536 ---- test/test.validate.js | 186 -- 43 files changed, 2714 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 .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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 061fb74..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T01:13:04.574Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -226,7 +219,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -288,11 +281,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 7e1d5f6..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/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index cb37286..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The function does not compile if provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The function does not compile if provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 c18fc08..1e2f2d8 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..79b9c4c --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,KAI7D,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,KCbR,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,IACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,GAG1B,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0576a9b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0N262', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4fa480d..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0N22h', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0N265', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0N261', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index afbe78e..3c07840 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer-array": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/random-base-randu": "^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", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..dbc487f --- /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 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 545e97df6796cbeedff25e2a43b543a5ef24b03b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:41:21 +0000 Subject: [PATCH 014/108] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbdba8c..0576a9b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0N262', shape ) ); } len = arguments.length; ndims = shape.length; diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..4fa480d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0N22h', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0N265', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0N261', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 1e52109..afbe78e 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.0.x", "@stdlib/ndarray-base-shape2strides": "^0.0.x", "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From c72ee0756d642561ff4bfa0fc332a68734068a62 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 13:55:20 +0000 Subject: [PATCH 015/108] Remove files --- index.d.ts | 74 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2768 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79b9c4c..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,KAI7D,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,KCbR,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,IACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,GAG1B,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index dbc487f..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 63454d37206e5d9bb837a22f2ac2e8a368ad53c2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 13:56:10 +0000 Subject: [PATCH 016/108] 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 | 41 +- benchmark/benchmark.js | 482 ---- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 -- benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 536 ---- test/test.validate.js | 186 -- 43 files changed, 2714 insertions(+), 4929 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 aa705a3..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T01:10:54.381Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -226,7 +219,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -288,11 +281,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 7e1d5f6..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/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index cb37286..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The function does not compile if provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The function does not compile if provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 c18fc08..1e2f2d8 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..79b9c4c --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,KAI7D,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,KCbR,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,IACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,GAG1B,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0576a9b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0N262', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4fa480d..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0N22h', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0N265', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0N261', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index afbe78e..3c07840 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer-array": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/random-base-randu": "^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", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5d01325 --- /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 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 6178744012e57e5cd15cd24cb425df4e50fdc69e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 03:54:32 +0000 Subject: [PATCH 017/108] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbdba8c..0576a9b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0N262', shape ) ); } len = arguments.length; ndims = shape.length; diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..4fa480d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0N22h', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0N265', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0N261', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 1e52109..afbe78e 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.0.x", "@stdlib/ndarray-base-shape2strides": "^0.0.x", "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 62aa7deac773284a3ed98e797d510dcc9a511828 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 18:08:18 +0000 Subject: [PATCH 018/108] Remove files --- index.d.ts | 74 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2768 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79b9c4c..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,KAI7D,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,KCbR,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,IACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,GAG1B,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5d01325..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From d7b213b359574a17af73ebe8a73733269e7d3b0e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 18:09:15 +0000 Subject: [PATCH 019/108] 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 | 41 +- benchmark/benchmark.js | 482 ---- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 -- benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 536 ---- test/test.validate.js | 186 -- 43 files changed, 2714 insertions(+), 4929 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 4d24826..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T01:35:47.823Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -226,7 +219,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -288,11 +281,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 7e1d5f6..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/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 c18fc08..1e2f2d8 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..79b9c4c --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,KAI7D,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,KCbR,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,IACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,GAG1B,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0576a9b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0N262', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4fa480d..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0N22h', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0N265', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0N261', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index afbe78e..3c07840 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer-array": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/random-base-randu": "^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", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a8ae5fc --- /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 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 9135a546529cad85cd2fe50c9a57abf5205cb3f1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 03:43:15 +0000 Subject: [PATCH 020/108] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbdba8c..0576a9b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0N262', shape ) ); } len = arguments.length; ndims = shape.length; diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..4fa480d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0N22h', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0N265', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0N261', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 1e52109..afbe78e 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.0.x", "@stdlib/ndarray-base-shape2strides": "^0.0.x", "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 4aa7738a4b20f57ca26675c7803b8df89c8c0521 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 14:26:53 +0000 Subject: [PATCH 021/108] Remove files --- index.d.ts | 74 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2768 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79b9c4c..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,KAI7D,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,KCbR,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,IACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,GAG1B,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a8ae5fc..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 00a38c1f8d4fb617098a3079e964945a3ee32a3e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 14:27:59 +0000 Subject: [PATCH 022/108] 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 | 41 +- benchmark/benchmark.js | 482 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 536 --- test/test.validate.js | 186 - 43 files changed, 4069 insertions(+), 4929 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 1d8cc46..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T01:24:01.632Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdceeb0..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: '19 19 * * 2' - - # 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 + + ```
@@ -226,7 +219,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -288,11 +281,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 7e1d5f6..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/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 c18fc08..1e2f2d8 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..79b9c4c --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0576a9b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0N262', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4fa480d..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0N22h', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0N265', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0N261', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index afbe78e..3c07840 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer-array": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/random-base-randu": "^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", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ee41014 --- /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 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 4cfae8dd7b5f2bde8dbdfb0bed8c5be0e8600fa1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 00:09:42 +0000 Subject: [PATCH 023/108] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbdba8c..0576a9b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0N262', shape ) ); } len = arguments.length; ndims = shape.length; diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..4fa480d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0N22h', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0N265', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0N261', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 1e52109..afbe78e 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.0.x", "@stdlib/ndarray-base-shape2strides": "^0.0.x", "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 399d0757b20faed03b6e582f394e262e2bfb79e9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 13:27:35 +0000 Subject: [PATCH 024/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4123 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79b9c4c..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ee41014..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 41b650903cd40db842037ce235e0fdc54f0f0046 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 13:28:36 +0000 Subject: [PATCH 025/108] 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 | 41 +- benchmark/benchmark.js | 482 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 536 --- test/test.validate.js | 186 - 43 files changed, 4069 insertions(+), 4950 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 782cecf..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T21:59:43.636Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdceeb0..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: '19 19 * * 2' - - # 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 + + ```
@@ -226,7 +219,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -288,11 +281,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 7e1d5f6..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/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 c18fc08..1e2f2d8 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..79b9c4c --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0576a9b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0N262', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4fa480d..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0N22h', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0N265', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0N261', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index afbe78e..3c07840 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer-array": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/random-base-randu": "^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", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f39b8c3 --- /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 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 71b9b2e9bea0c7a25d973f39b87921185a2c528c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 04:01:28 +0000 Subject: [PATCH 026/108] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbdba8c..0576a9b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0N262', shape ) ); } len = arguments.length; ndims = shape.length; diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..4fa480d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0N22h', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0N265', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0N261', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 90e0c8e..6c19ef5 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.0.x", "@stdlib/ndarray-base-shape2strides": "^0.0.x", "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From a8bb6b3c934be3552395791956117469c245ab5f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 11:30:11 +0000 Subject: [PATCH 027/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4123 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79b9c4c..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f39b8c3..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From d8f0da35799e634139027691add18c4dc70e50ac Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 11:31:10 +0000 Subject: [PATCH 028/108] 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 | 41 +- benchmark/benchmark.js | 482 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 536 --- test/test.validate.js | 186 - 43 files changed, 4069 insertions(+), 4955 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 d980b72..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T01:49:30.734Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdceeb0..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: '19 19 * * 2' - - # 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 + + ```
@@ -226,7 +219,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -288,11 +281,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 7e1d5f6..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/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 c18fc08..1e2f2d8 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..79b9c4c --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0576a9b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0N262', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4fa480d..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0N22h', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0N265', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0N261', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 6c19ef5..3c07840 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer-array": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/random-base-randu": "^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", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3c2edbc --- /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 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From f5b21abb360197158bdae285ed234d3b4321620a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 02:56:06 +0000 Subject: [PATCH 029/108] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbdba8c..0576a9b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0N262', shape ) ); } len = arguments.length; ndims = shape.length; diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..4fa480d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0N22h', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0N265', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0N261', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 175cf69..71bb125 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.0.x", "@stdlib/ndarray-base-shape2strides": "^0.0.x", "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 1290d8803eb1f3acdbd64ce554c8ec68e3b50635 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 12:32:08 +0000 Subject: [PATCH 030/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4123 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 79b9c4c..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3c2edbc..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 07d196c7ca04b652c75403749e23cc1ff9a8b584 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 12:33:07 +0000 Subject: [PATCH 031/108] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 791 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 184 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 41 +- benchmark/benchmark.js | 482 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 536 --- test/test.validate.js | 186 - 43 files changed, 4069 insertions(+), 4966 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 dd3691d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-01-01T01:14:16.310Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdceeb0..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: '19 19 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -226,7 +219,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -288,11 +281,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 7e1d5f6..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/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 c18fc08..1e2f2d8 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..71fecd8 --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0576a9b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0N262', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4fa480d..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0N22h', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0N265', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0N261', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 71bb125..3c07840 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer-array": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ee439bb --- /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 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From beaa2a67b985b8333e2795baa61c1e4cb22c9c75 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 04:33:12 +0000 Subject: [PATCH 032/108] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbdba8c..0576a9b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0N262', shape ) ); } len = arguments.length; ndims = shape.length; diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..4fa480d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0N22h', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0N265', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0N261', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 175cf69..71bb125 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.0.x", "@stdlib/ndarray-base-shape2strides": "^0.0.x", "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From d0fa7ba3e2e0fc198d813f39580b9afd08f5c5e2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 16:55:22 +0000 Subject: [PATCH 033/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4123 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 71fecd8..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ee439bb..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 4f79e44b06fbadc894b6fb3886dbb7b674db4efd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 16:56:18 +0000 Subject: [PATCH 034/108] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 791 --- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 184 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 482 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 536 -- test/test.validate.js | 186 - 43 files changed, 6202 insertions(+), 4966 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 db747f5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T01:37:54.509Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdceeb0..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: '19 19 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -226,7 +219,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -288,11 +281,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 7e1d5f6..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/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 c18fc08..1e2f2d8 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..71fecd8 --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0576a9b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0N262', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4fa480d..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0N22h', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0N265', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0N261', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 71bb125..3c07840 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer-array": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-sub2ind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4559862 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 2cfca6a8cdc725bb07739be43a03474f4f8b187a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 06:11:49 +0000 Subject: [PATCH 035/108] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbdba8c..0576a9b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0N262', shape ) ); } len = arguments.length; ndims = shape.length; diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..4fa480d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0N22h', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0N265', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0N261', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 7ffd7cc..502e3a2 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.0.7", "@stdlib/ndarray-base-shape2strides": "^0.0.8", "@stdlib/ndarray-base-sub2ind": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From e01d02eb773c0ab5f828b421567138ec95993130 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 14:58:05 +0000 Subject: [PATCH 036/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6256 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 71fecd8..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4559862..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a626cab042b133d4306c901c806618900b67072a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 14:59:24 +0000 Subject: [PATCH 037/108] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 236 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 482 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 536 -- test/test.validate.js | 186 - 43 files changed, 6202 insertions(+), 5101 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 70836d1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-03-01T03:59:29.254Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdceeb0..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: '19 19 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -226,7 +219,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -288,11 +281,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 644ccea..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 c18fc08..1e2f2d8 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..71fecd8 --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0576a9b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0N262', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4fa480d..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0N22h', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0N265', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0N261', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 502e3a2..aa9bb65 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/assert-is-nonnegative-integer-array": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.0.7", - "@stdlib/ndarray-base-assert-is-order": "^0.0.7", - "@stdlib/ndarray-base-shape2strides": "^0.0.8", - "@stdlib/ndarray-base-sub2ind": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-floor": "^0.0.8", - "@stdlib/ndarray-base-numel": "^0.0.8", - "@stdlib/random-base-discrete-uniform": "^0.0.6", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..8dff0a1 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 94e605133ec05594ec8de86a72fb81b467f7dce2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 06:46:43 +0000 Subject: [PATCH 038/108] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbdba8c..0576a9b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0N262', shape ) ); } len = arguments.length; ndims = shape.length; diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..4fa480d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0N22h', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0N265', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0N261', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 7ffd7cc..502e3a2 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.0.7", "@stdlib/ndarray-base-shape2strides": "^0.0.8", "@stdlib/ndarray-base-sub2ind": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From 1314e3f35d84cd0037ec51b1b8895259442e4930 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 14:05:09 +0000 Subject: [PATCH 039/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6256 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 71fecd8..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 8dff0a1..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b07b2b310b76226c103d05273298bd216f486c58 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 14:06:06 +0000 Subject: [PATCH 040/108] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 482 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 536 -- test/test.validate.js | 186 - 43 files changed, 6202 insertions(+), 5107 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 7a161d3..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-04-01T04:33:53.802Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdceeb0..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: '19 19 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -226,7 +219,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -288,11 +281,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 644ccea..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 c18fc08..1e2f2d8 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..71fecd8 --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0576a9b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0N262', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4fa480d..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0N22h', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0N265', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0N261', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 502e3a2..aa9bb65 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/assert-is-nonnegative-integer-array": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.0.7", - "@stdlib/ndarray-base-assert-is-order": "^0.0.7", - "@stdlib/ndarray-base-shape2strides": "^0.0.8", - "@stdlib/ndarray-base-sub2ind": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-floor": "^0.0.8", - "@stdlib/ndarray-base-numel": "^0.0.8", - "@stdlib/random-base-discrete-uniform": "^0.0.6", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a062863 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 4113744cc3f89cf9b0fa7caacb6f2ad4981db6a7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 06:31:03 +0000 Subject: [PATCH 041/108] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbdba8c..0576a9b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0N262', shape ) ); } len = arguments.length; ndims = shape.length; diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..4fa480d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0N22h', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0N265', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0N261', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 7ffd7cc..502e3a2 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.0.7", "@stdlib/ndarray-base-shape2strides": "^0.0.8", "@stdlib/ndarray-base-sub2ind": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From 633ee59c52a3e7e112fa62688b70d3eba7c90d33 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 13:39:58 +0000 Subject: [PATCH 042/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6256 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 71fecd8..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a062863..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 671a366d892392f0c4e0661ac3bf38ffc888a7d4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 13:41:06 +0000 Subject: [PATCH 043/108] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 482 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 536 -- test/test.validate.js | 186 - 43 files changed, 6202 insertions(+), 5107 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 46d52f7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-05-01T04:19:32.309Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdceeb0..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: '19 19 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -226,7 +219,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -288,11 +281,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 644ccea..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 c18fc08..1e2f2d8 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..71fecd8 --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0576a9b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0N262', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4fa480d..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0N22h', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0N265', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0N261', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 502e3a2..aa9bb65 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/assert-is-nonnegative-integer-array": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.0.7", - "@stdlib/ndarray-base-assert-is-order": "^0.0.7", - "@stdlib/ndarray-base-shape2strides": "^0.0.8", - "@stdlib/ndarray-base-sub2ind": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-floor": "^0.0.8", - "@stdlib/ndarray-base-numel": "^0.0.8", - "@stdlib/random-base-discrete-uniform": "^0.0.6", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d252c72 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From f3946565cd762fa11a9798a762cdd94dd8fbcef6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 06:10:23 +0000 Subject: [PATCH 044/108] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbdba8c..0576a9b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0N262', shape ) ); } len = arguments.length; ndims = shape.length; diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..4fa480d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0N22h', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0N265', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0N261', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 7ffd7cc..502e3a2 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.0.7", "@stdlib/ndarray-base-shape2strides": "^0.0.8", "@stdlib/ndarray-base-sub2ind": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From c01b01bb842f76a98d40b16cc03c08052515d91f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 13:48:55 +0000 Subject: [PATCH 045/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6256 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 71fecd8..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d252c72..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e5f5b2ef740d8f2dc5dafb6a38279328d345417f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 13:49:58 +0000 Subject: [PATCH 046/108] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 482 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 536 -- test/test.validate.js | 186 - 43 files changed, 6202 insertions(+), 5107 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 37239cf..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-06-01T03:58:56.453Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdceeb0..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: '19 19 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -226,7 +219,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -288,11 +281,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 644ccea..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 c18fc08..1e2f2d8 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..71fecd8 --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0576a9b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0N262', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4fa480d..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0N22h', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0N265', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0N261', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 502e3a2..aa9bb65 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/assert-is-nonnegative-integer-array": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.0.7", - "@stdlib/ndarray-base-assert-is-order": "^0.0.7", - "@stdlib/ndarray-base-shape2strides": "^0.0.8", - "@stdlib/ndarray-base-sub2ind": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-floor": "^0.0.8", - "@stdlib/ndarray-base-numel": "^0.0.8", - "@stdlib/random-base-discrete-uniform": "^0.0.6", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..80b4050 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From eb03b5096bc73119eb306c2fba48a68b2c054c18 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 06:12:36 +0000 Subject: [PATCH 047/108] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index dbdba8c..0576a9b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0N262', shape ) ); } len = arguments.length; ndims = shape.length; diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..4fa480d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0N22h', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0N265', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0N261', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 7ffd7cc..502e3a2 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.0.7", "@stdlib/ndarray-base-shape2strides": "^0.0.8", "@stdlib/ndarray-base-sub2ind": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From 3df2e841fa608a52cfe48505172079dc685d8fe5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 14:01:29 +0000 Subject: [PATCH 048/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6256 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 71fecd8..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 80b4050..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8ac659257a577adc25dc5bba1c79f404c86f2c99 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 14:02:24 +0000 Subject: [PATCH 049/108] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 482 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 536 -- test/test.validate.js | 186 - 43 files changed, 6202 insertions(+), 5107 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 13f3587..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-07-01T03:59:25.024Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdceeb0..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: '19 19 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -226,7 +219,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -288,11 +281,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 644ccea..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 c18fc08..1e2f2d8 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..71fecd8 --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0576a9b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0N262', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4fa480d..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0N22h', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0N265', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0N261', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 502e3a2..aa9bb65 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/assert-is-nonnegative-integer-array": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.0.7", - "@stdlib/ndarray-base-assert-is-order": "^0.0.7", - "@stdlib/ndarray-base-shape2strides": "^0.0.8", - "@stdlib/ndarray-base-sub2ind": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-floor": "^0.0.8", - "@stdlib/ndarray-base-numel": "^0.0.8", - "@stdlib/random-base-discrete-uniform": "^0.0.6", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7a1246c --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From e179781a11be65a277b9422a57761609af37a978 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 06:40:32 +0000 Subject: [PATCH 050/108] Transform error messages --- lib/main.js | 4 ++-- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index b608a7b..94c05b8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -74,7 +74,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0N262', shape ) ); } len = arguments.length; ndims = shape.length; diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..4fa480d 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0N22h', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0N265', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0N261', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 7ffd7cc..502e3a2 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.0.7", "@stdlib/ndarray-base-shape2strides": "^0.0.8", "@stdlib/ndarray-base-sub2ind": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From 986df5562d6d1152bdb2182663c0424c5b1c599d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 15:12:48 +0000 Subject: [PATCH 051/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6256 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 71fecd8..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7a1246c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 64a9f0616beaf37d53e51b974904d8cb9d0cb991 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 15:13:57 +0000 Subject: [PATCH 052/108] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 482 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 117 - lib/validate.js | 84 - package.json | 66 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 536 -- test/test.validate.js | 186 - 43 files changed, 6202 insertions(+), 5106 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 e789e8d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-08-01T04:23:16.754Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdceeb0..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: '19 19 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 334eb59..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -226,7 +219,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -288,11 +281,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 644ccea..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 c18fc08..1e2f2d8 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..71fecd8 --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCfA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 94c05b8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0N262', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4fa480d..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0N22h', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0N265', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0N260', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0N261', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 502e3a2..aa9bb65 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.7", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/assert-is-nonnegative-integer-array": "^0.0.8", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.0.7", - "@stdlib/ndarray-base-assert-is-order": "^0.0.7", - "@stdlib/ndarray-base-shape2strides": "^0.0.8", - "@stdlib/ndarray-base-sub2ind": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-floor": "^0.0.8", - "@stdlib/ndarray-base-numel": "^0.0.8", - "@stdlib/random-base-discrete-uniform": "^0.0.6", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2071f2c --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 2fc31ab4885fa1809cc02f11bc5b2acddc90c219 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 16:36:57 +0000 Subject: [PATCH 053/108] Transform error messages --- lib/main.js | 8 ++++---- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/main.js b/lib/main.js index b608a7b..94a70a8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -74,7 +74,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0kF5o,LH', shape ) ); } len = arguments.length; ndims = shape.length; @@ -95,7 +95,7 @@ function sub2ind() { } i = 1; if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); + throw new RangeError( format( '0kF5p,LI', ndims, j-i ) ); } args = new Array( ndims+4 ); args[ 0 ] = shape; @@ -103,7 +103,7 @@ function sub2ind() { args[ 2 ] = 0; // strides are positive, so offset is always zero for ( ; i < j; i++ ) { if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); + throw new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) ); } args[ i+2 ] = arguments[ i ]; } diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..0d5fc73 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0kF2V,FD', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0kF5r,LK', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0kF5m,LL', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0kF5n,LM', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 37b03e6..e845127 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.1.0", "@stdlib/ndarray-base-shape2strides": "^0.1.0", "@stdlib/ndarray-base-sub2ind": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 0986795ceaeb30c98168eb7fa3202947e1632ec6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 17:57:38 +0000 Subject: [PATCH 054/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6256 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 1e2f2d8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 71fecd8..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0N22h",e));if(i(e,"mode")){if(r.mode=e.mode,n(r.mode)){if(0===r.mode.length)return new TypeError(d("0N265","mode"))}else r.mode=[r.mode];for(s=0;si+1){if(a=p(m,arguments[f=h-1]))throw a}else f=h;if(f-(j=1)!==i)throw new RangeError(d("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",i,f-j));for((n=new Array(i+4))[0]=o,n[1]=s(o,m.order),n[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;s+BAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,QAASJ,IAExC,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,QAAS,cAFvCL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,QAAS,OAAQL,EAAKO,KAAML,IAG5D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,QAAS,QAASL,EAAKW,QAGhD,IACR,CCfA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,QAASS,IASvC,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2071f2c..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 04d65ad0a8a3dc3764cd0224850b45085d72a977 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 17:59:36 +0000 Subject: [PATCH 055/108] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 783 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 482 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 117 - lib/validate.js | 84 - package.json | 66 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 536 -- test/test.validate.js | 186 - 46 files changed, 6202 insertions(+), 5142 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 354a50a..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 fdceeb0..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: '19 19 * * 2' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -237,7 +230,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -299,11 +292,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 644ccea..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/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 f14e96a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sub2ind from '../docs/types/index'; -export = sub2ind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a32fda4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var m=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var g=m(function(k,h){h.exports={mode:["throw"],order:"row-major"}});var p=m(function(F,f){ -var q=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),y=require('@stdlib/assert-is-array/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),O=require('@stdlib/ndarray-base-assert-is-index-mode/dist'),d=require('@stdlib/error-tools-fmtprodmsg/dist');function T(e,r){var i;if(!q(r))return new TypeError(d('0kF2V',r));if(l(r,"mode")){if(e.mode=r.mode,!y(e.mode))e.mode=[e.mode];else if(e.mode.length===0)return new TypeError(d('0kF5r',"mode"));for(i=0;ii+1){if(o=u-1,e=arguments[o],s=N(t,e),s)throw s}else o=u;if(n=1,o-n!==i)throw new RangeError(v('0kF5p',i,o-n));for(a=new Array(i+4),a[0]=r,a[1]=A(r,t.order),a[2]=0;n ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,CAAE,OAAQ,EAClB,MAAS,WACV,ICHA,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAU,QAAS,sCAAuC,EAC1DC,EAAc,QAAS,2CAA4C,EACnEC,EAAS,QAAS,uBAAwB,EA0B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,IAAI,EACJ,GAAK,CAACR,EAAUQ,CAAQ,EACvB,OAAO,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE/G,GAAKP,EAAYO,EAAS,MAAO,EAAI,CAEpC,GADAD,EAAK,KAAOC,EAAQ,KACf,CAACN,EAASK,EAAK,IAAK,EACxBA,EAAK,KAAO,CAAEA,EAAK,IAAK,UACbA,EAAK,KAAK,SAAW,EAChC,OAAO,IAAI,UAAWF,EAAQ,wDAAyD,MAAO,CAAE,EAEjG,IAAM,EAAI,EAAG,EAAIE,EAAK,KAAK,OAAQ,IAClC,GAAK,CAACH,EAAaG,EAAK,KAAM,CAAE,CAAE,EACjC,OAAO,IAAI,UAAWF,EAAQ,iFAAkF,OAAQE,EAAK,KAAM,CAAE,CAAE,CAAE,CAG5I,CACA,OAAKN,EAAYO,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACL,EAASI,EAAK,KAAM,GAClB,IAAI,UAAWF,EAAQ,kFAAmF,QAASE,EAAK,KAAM,CAAE,EAGlI,IACR,CAKAR,EAAO,QAAUO,ICnFjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAW,QAAS,8BAA+B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IAmCf,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAP,EAAQ,UAAW,CAAE,EAChB,CAACT,EAA2BS,CAAM,EACtC,MAAM,IAAI,UAAWL,EAAQ,8GAA+GK,CAAM,CAAE,EASrJ,GAPAK,EAAM,UAAU,OAChBJ,EAAQD,EAAM,OAEdG,EAAO,CAAC,EACRA,EAAK,KAAOP,EAAS,KAAK,MAAM,EAChCO,EAAK,MAAQP,EAAS,MAEjBS,EAAMJ,EAAM,GAIhB,GAHAM,EAAIF,EAAM,EACVN,EAAU,UAAWQ,CAAE,EACvBH,EAAMP,EAAUM,EAAMJ,CAAQ,EACzBK,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GADAC,EAAI,EACCC,EAAED,IAAML,EACZ,MAAM,IAAI,WAAYN,EAAQ,gIAAiIM,EAAOM,EAAED,CAAE,CAAE,EAM7K,IAJAJ,EAAO,IAAI,MAAOD,EAAM,CAAE,EAC1BC,EAAM,CAAE,EAAIF,EACZE,EAAM,CAAE,EAAIT,EAAeO,EAAOG,EAAK,KAAM,EAC7CD,EAAM,CAAE,EAAI,EACJI,EAAIC,EAAGD,IAAM,CACpB,GAAK,CAACd,EAAW,UAAWc,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oFAAqFW,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEvIJ,EAAMI,EAAE,CAAE,EAAI,UAAWA,CAAE,CAC5B,CACA,OAAAJ,EAAMI,EAAE,CAAE,EAAIH,EAAK,KACZT,EAAS,MAAO,KAAMQ,CAAK,CACnC,CAKAZ,EAAO,QAAUQ,IClFjB,IAAIU,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isArray", "isOrder", "isIndexMode", "format", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeIntegerArray", "isInteger", "shape2strides", "getIndex", "format", "defaults", "validate", "sub2ind", "options", "shape", "ndims", "args", "opts", "err", "len", "i", "j", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 1d6c0b9..a0eca41 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bd4c25e --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.1.0-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0kF2V,FD",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r,LK","mode"))}else r.mode=[r.mode];for(s=0;sn+1){if(a=p(m,arguments[f=j-1]))throw a}else f=j;if(f-(h=1)!==n)throw new RangeError(d("0kF5p,LI",n,f-h));for((i=new Array(n+4))[0]=o,i[1]=s(o,m.order),i[2]=0;h ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p,LI', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;8hCAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,WAAYJ,IAE3C,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,WAAY,cAF1CL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,WAAY,OAAQL,EAAKO,KAAML,IAG/D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,WAAY,QAASL,EAAKW,QAGnD,IACR,CCfA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,WAAYS,IAS1C,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,WAAYU,EAAOI,EAAEjB,IAMpD,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,EAAGmB,UAAWnB,KAExDc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 94a70a8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0kF5o,LH', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( '0kF5p,LI', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0d5fc73..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0kF2V,FD', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0kF5r,LK', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0kF5m,LL', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0kF5n,LM', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index e845127..a0c93a6 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.0", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.0", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.1.0", - "@stdlib/ndarray-base-assert-is-order": "^0.1.0", - "@stdlib/ndarray-base-shape2strides": "^0.1.0", - "@stdlib/ndarray-base-sub2ind": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/random-base-discrete-uniform": "^0.0.6", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7720191 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From cdffca360a6f24c346fa69913b67446ec96abd32 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 18:17:14 +0000 Subject: [PATCH 056/108] Update README.md for ESM bundle v0.1.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 735b770..309c0fc 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import sub2ind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-sub2ind@esm/index.mjs'; +import sub2ind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-sub2ind@v0.1.0-esm/index.mjs'; ``` #### sub2ind( shape, ...subscripts\[, options] ) @@ -146,7 +146,7 @@ var idx = sub2ind( shape, -2, 10, -1, opts ); - - - - From 38c0110a02737aea569174529e7502dbff39cb36 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 2 Oct 2023 13:26:27 +0000 Subject: [PATCH 060/108] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 482 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 117 - lib/validate.js | 84 - package.json | 66 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 536 -- test/test.js | 536 -- test/test.validate.js | 186 - 48 files changed, 6202 insertions(+), 5737 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 4609151..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T02:54:48.898Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 5cd5c02..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6e1404c..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: '19 19 * * 2' - - # 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 + + ```
@@ -237,7 +230,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -299,11 +292,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 644ccea..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/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 f14e96a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sub2ind from '../docs/types/index'; -export = sub2ind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a32fda4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var m=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var g=m(function(k,h){h.exports={mode:["throw"],order:"row-major"}});var p=m(function(F,f){ -var q=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),y=require('@stdlib/assert-is-array/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),O=require('@stdlib/ndarray-base-assert-is-index-mode/dist'),d=require('@stdlib/error-tools-fmtprodmsg/dist');function T(e,r){var i;if(!q(r))return new TypeError(d('0kF2V',r));if(l(r,"mode")){if(e.mode=r.mode,!y(e.mode))e.mode=[e.mode];else if(e.mode.length===0)return new TypeError(d('0kF5r',"mode"));for(i=0;ii+1){if(o=u-1,e=arguments[o],s=N(t,e),s)throw s}else o=u;if(n=1,o-n!==i)throw new RangeError(v('0kF5p',i,o-n));for(a=new Array(i+4),a[0]=r,a[1]=A(r,t.order),a[2]=0;n ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,CAAE,OAAQ,EAClB,MAAS,WACV,ICHA,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAU,QAAS,sCAAuC,EAC1DC,EAAc,QAAS,2CAA4C,EACnEC,EAAS,QAAS,uBAAwB,EA0B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,IAAI,EACJ,GAAK,CAACR,EAAUQ,CAAQ,EACvB,OAAO,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE/G,GAAKP,EAAYO,EAAS,MAAO,EAAI,CAEpC,GADAD,EAAK,KAAOC,EAAQ,KACf,CAACN,EAASK,EAAK,IAAK,EACxBA,EAAK,KAAO,CAAEA,EAAK,IAAK,UACbA,EAAK,KAAK,SAAW,EAChC,OAAO,IAAI,UAAWF,EAAQ,wDAAyD,MAAO,CAAE,EAEjG,IAAM,EAAI,EAAG,EAAIE,EAAK,KAAK,OAAQ,IAClC,GAAK,CAACH,EAAaG,EAAK,KAAM,CAAE,CAAE,EACjC,OAAO,IAAI,UAAWF,EAAQ,iFAAkF,OAAQE,EAAK,KAAM,CAAE,CAAE,CAAE,CAG5I,CACA,OAAKN,EAAYO,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACL,EAASI,EAAK,KAAM,GAClB,IAAI,UAAWF,EAAQ,kFAAmF,QAASE,EAAK,KAAM,CAAE,EAGlI,IACR,CAKAR,EAAO,QAAUO,ICnFjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAW,QAAS,8BAA+B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IAmCf,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAP,EAAQ,UAAW,CAAE,EAChB,CAACT,EAA2BS,CAAM,EACtC,MAAM,IAAI,UAAWL,EAAQ,8GAA+GK,CAAM,CAAE,EASrJ,GAPAK,EAAM,UAAU,OAChBJ,EAAQD,EAAM,OAEdG,EAAO,CAAC,EACRA,EAAK,KAAOP,EAAS,KAAK,MAAM,EAChCO,EAAK,MAAQP,EAAS,MAEjBS,EAAMJ,EAAM,GAIhB,GAHAM,EAAIF,EAAM,EACVN,EAAU,UAAWQ,CAAE,EACvBH,EAAMP,EAAUM,EAAMJ,CAAQ,EACzBK,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GADAC,EAAI,EACCC,EAAED,IAAML,EACZ,MAAM,IAAI,WAAYN,EAAQ,gIAAiIM,EAAOM,EAAED,CAAE,CAAE,EAM7K,IAJAJ,EAAO,IAAI,MAAOD,EAAM,CAAE,EAC1BC,EAAM,CAAE,EAAIF,EACZE,EAAM,CAAE,EAAIT,EAAeO,EAAOG,EAAK,KAAM,EAC7CD,EAAM,CAAE,EAAI,EACJI,EAAIC,EAAGD,IAAM,CACpB,GAAK,CAACd,EAAW,UAAWc,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oFAAqFW,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEvIJ,EAAMI,EAAE,CAAE,EAAI,UAAWA,CAAE,CAC5B,CACA,OAAAJ,EAAMI,EAAE,CAAE,EAAIH,EAAK,KACZT,EAAS,MAAO,KAAMQ,CAAK,CACnC,CAKAZ,EAAO,QAAUQ,IClFjB,IAAIU,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isArray", "isOrder", "isIndexMode", "format", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeIntegerArray", "isInteger", "shape2strides", "getIndex", "format", "defaults", "validate", "sub2ind", "options", "shape", "ndims", "args", "opts", "err", "len", "i", "j", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 1d6c0b9..a0eca41 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..761781c --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.1.0-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0kF2V,FD",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r,LK","mode"))}else r.mode=[r.mode];for(s=0;sn+1){if(a=p(m,arguments[f=j-1]))throw a}else f=j;if(f-(h=1)!==n)throw new RangeError(d("0kF5p,LI",n,f-h));for((i=new Array(n+4))[0]=o,i[1]=s(o,m.order),i[2]=0;h ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p,LI', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,WAAYJ,IAE3C,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,WAAY,cAF1CL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,WAAY,OAAQL,EAAKO,KAAML,IAG/D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,WAAY,QAASL,EAAKW,QAGnD,IACR,CCfA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,WAAYS,IAS1C,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,WAAYU,EAAOI,EAAEjB,IAMpD,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,EAAGmB,UAAWnB,KAExDc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 94a70a8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0kF5o,LH', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( '0kF5p,LI', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0d5fc73..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0kF2V,FD', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0kF5r,LK', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0kF5m,LL', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0kF5n,LM', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 6de563a..a0c93a6 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.0", - "@stdlib/assert-is-array": "^0.1.0", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.0", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.1.0", - "@stdlib/ndarray-base-assert-is-order": "^0.1.0", - "@stdlib/ndarray-base-shape2strides": "^0.1.0", - "@stdlib/ndarray-base-sub2ind": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/random-base-discrete-uniform": "^0.1.0", - "@stdlib/random-base-randu": "^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", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c8a9d94 --- /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 85e7bf1..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From d26ad117981e8c240f14663a54c946e22a242d14 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 11:36:51 +0000 Subject: [PATCH 061/108] Transform error messages --- lib/main.js | 8 ++++---- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/main.js b/lib/main.js index b608a7b..94a70a8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -74,7 +74,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0kF5o,LH', shape ) ); } len = arguments.length; ndims = shape.length; @@ -95,7 +95,7 @@ function sub2ind() { } i = 1; if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); + throw new RangeError( format( '0kF5p,LI', ndims, j-i ) ); } args = new Array( ndims+4 ); args[ 0 ] = shape; @@ -103,7 +103,7 @@ function sub2ind() { args[ 2 ] = 0; // strides are positive, so offset is always zero for ( ; i < j; i++ ) { if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); + throw new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) ); } args[ i+2 ] = arguments[ i ]; } diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..0d5fc73 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0kF2V,FD', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0kF5r,LK', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0kF5m,LL', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0kF5n,LM', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 8caea1d..964f415 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.1.1", "@stdlib/ndarray-base-shape2strides": "^0.1.1", "@stdlib/ndarray-base-sub2ind": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 5cc2ebf3a05363a0951e25d877a1f4f1281e835a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 6 Oct 2023 15:02:02 +0000 Subject: [PATCH 062/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6256 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 a0eca41..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 761781c..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.1.0-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0kF2V,FD",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r,LK","mode"))}else r.mode=[r.mode];for(s=0;sn+1){if(a=p(m,arguments[f=j-1]))throw a}else f=j;if(f-(h=1)!==n)throw new RangeError(d("0kF5p,LI",n,f-h));for((i=new Array(n+4))[0]=o,i[1]=s(o,m.order),i[2]=0;h ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p,LI', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,WAAYJ,IAE3C,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,WAAY,cAF1CL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,WAAY,OAAQL,EAAKO,KAAML,IAG/D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,WAAY,QAASL,EAAKW,QAGnD,IACR,CCfA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,WAAYS,IAS1C,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,WAAYU,EAAOI,EAAEjB,IAMpD,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,EAAGmB,UAAWnB,KAExDc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c8a9d94..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 97e6e4b4137aa1324444b1b557229fe58d4ac801 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 6 Oct 2023 15:05:37 +0000 Subject: [PATCH 063/108] 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 | 41 +- benchmark/benchmark.js | 482 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 117 - lib/validate.js | 84 - package.json | 66 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 536 -- test/test.js | 536 -- test/test.validate.js | 186 - 47 files changed, 6202 insertions(+), 5736 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 5cd5c02..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6e1404c..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: '19 19 * * 2' - - # 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 + + ```
@@ -237,7 +230,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -299,11 +292,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 644ccea..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/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 f14e96a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sub2ind from '../docs/types/index'; -export = sub2ind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a32fda4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var m=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var g=m(function(k,h){h.exports={mode:["throw"],order:"row-major"}});var p=m(function(F,f){ -var q=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),y=require('@stdlib/assert-is-array/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),O=require('@stdlib/ndarray-base-assert-is-index-mode/dist'),d=require('@stdlib/error-tools-fmtprodmsg/dist');function T(e,r){var i;if(!q(r))return new TypeError(d('0kF2V',r));if(l(r,"mode")){if(e.mode=r.mode,!y(e.mode))e.mode=[e.mode];else if(e.mode.length===0)return new TypeError(d('0kF5r',"mode"));for(i=0;ii+1){if(o=u-1,e=arguments[o],s=N(t,e),s)throw s}else o=u;if(n=1,o-n!==i)throw new RangeError(v('0kF5p',i,o-n));for(a=new Array(i+4),a[0]=r,a[1]=A(r,t.order),a[2]=0;n ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,CAAE,OAAQ,EAClB,MAAS,WACV,ICHA,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAU,QAAS,sCAAuC,EAC1DC,EAAc,QAAS,2CAA4C,EACnEC,EAAS,QAAS,uBAAwB,EA0B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,IAAI,EACJ,GAAK,CAACR,EAAUQ,CAAQ,EACvB,OAAO,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE/G,GAAKP,EAAYO,EAAS,MAAO,EAAI,CAEpC,GADAD,EAAK,KAAOC,EAAQ,KACf,CAACN,EAASK,EAAK,IAAK,EACxBA,EAAK,KAAO,CAAEA,EAAK,IAAK,UACbA,EAAK,KAAK,SAAW,EAChC,OAAO,IAAI,UAAWF,EAAQ,wDAAyD,MAAO,CAAE,EAEjG,IAAM,EAAI,EAAG,EAAIE,EAAK,KAAK,OAAQ,IAClC,GAAK,CAACH,EAAaG,EAAK,KAAM,CAAE,CAAE,EACjC,OAAO,IAAI,UAAWF,EAAQ,iFAAkF,OAAQE,EAAK,KAAM,CAAE,CAAE,CAAE,CAG5I,CACA,OAAKN,EAAYO,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACL,EAASI,EAAK,KAAM,GAClB,IAAI,UAAWF,EAAQ,kFAAmF,QAASE,EAAK,KAAM,CAAE,EAGlI,IACR,CAKAR,EAAO,QAAUO,ICnFjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAW,QAAS,8BAA+B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IAmCf,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAP,EAAQ,UAAW,CAAE,EAChB,CAACT,EAA2BS,CAAM,EACtC,MAAM,IAAI,UAAWL,EAAQ,8GAA+GK,CAAM,CAAE,EASrJ,GAPAK,EAAM,UAAU,OAChBJ,EAAQD,EAAM,OAEdG,EAAO,CAAC,EACRA,EAAK,KAAOP,EAAS,KAAK,MAAM,EAChCO,EAAK,MAAQP,EAAS,MAEjBS,EAAMJ,EAAM,GAIhB,GAHAM,EAAIF,EAAM,EACVN,EAAU,UAAWQ,CAAE,EACvBH,EAAMP,EAAUM,EAAMJ,CAAQ,EACzBK,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GADAC,EAAI,EACCC,EAAED,IAAML,EACZ,MAAM,IAAI,WAAYN,EAAQ,gIAAiIM,EAAOM,EAAED,CAAE,CAAE,EAM7K,IAJAJ,EAAO,IAAI,MAAOD,EAAM,CAAE,EAC1BC,EAAM,CAAE,EAAIF,EACZE,EAAM,CAAE,EAAIT,EAAeO,EAAOG,EAAK,KAAM,EAC7CD,EAAM,CAAE,EAAI,EACJI,EAAIC,EAAGD,IAAM,CACpB,GAAK,CAACd,EAAW,UAAWc,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oFAAqFW,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEvIJ,EAAMI,EAAE,CAAE,EAAI,UAAWA,CAAE,CAC5B,CACA,OAAAJ,EAAMI,EAAE,CAAE,EAAIH,EAAK,KACZT,EAAS,MAAO,KAAMQ,CAAK,CACnC,CAKAZ,EAAO,QAAUQ,IClFjB,IAAIU,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isArray", "isOrder", "isIndexMode", "format", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeIntegerArray", "isInteger", "shape2strides", "getIndex", "format", "defaults", "validate", "sub2ind", "options", "shape", "ndims", "args", "opts", "err", "len", "i", "j", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 1d6c0b9..a0eca41 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..979f673 --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.1.1-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0kF2V,FD",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r,LK","mode"))}else r.mode=[r.mode];for(s=0;sn+1){if(a=p(m,arguments[f=j-1]))throw a}else f=j;if(f-(h=1)!==n)throw new RangeError(d("0kF5p,LI",n,f-h));for((i=new Array(n+4))[0]=o,i[1]=s(o,m.order),i[2]=0;h ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p,LI', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,WAAYJ,IAE3C,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,WAAY,cAF1CL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,WAAY,OAAQL,EAAKO,KAAML,IAG/D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,WAAY,QAASL,EAAKW,QAGnD,IACR,CCfA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,WAAYS,IAS1C,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,WAAYU,EAAOI,EAAEjB,IAMpD,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,EAAGmB,UAAWnB,KAExDc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 94a70a8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0kF5o,LH', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( '0kF5p,LI', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0d5fc73..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0kF2V,FD', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0kF5r,LK', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0kF5m,LL', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0kF5n,LM', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 964f415..a0c93a6 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@stdlib/ndarray-base-shape2strides": "^0.1.1", - "@stdlib/ndarray-base-sub2ind": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/random-base-discrete-uniform": "^0.1.0", - "@stdlib/random-base-randu": "^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", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..cc303fa --- /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 85e7bf1..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 8e09642866886c077e3de09a017bc6004bf6c52c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 08:19:09 +0000 Subject: [PATCH 064/108] Transform error messages --- lib/main.js | 8 ++++---- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/main.js b/lib/main.js index b608a7b..94a70a8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -74,7 +74,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0kF5o,LH', shape ) ); } len = arguments.length; ndims = shape.length; @@ -95,7 +95,7 @@ function sub2ind() { } i = 1; if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); + throw new RangeError( format( '0kF5p,LI', ndims, j-i ) ); } args = new Array( ndims+4 ); args[ 0 ] = shape; @@ -103,7 +103,7 @@ function sub2ind() { args[ 2 ] = 0; // strides are positive, so offset is always zero for ( ; i < j; i++ ) { if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); + throw new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) ); } args[ i+2 ] = arguments[ i ]; } diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..0d5fc73 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0kF2V,FD', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0kF5r,LK', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0kF5m,LL', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0kF5n,LM', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 2357949..2b503f9 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.1.1", "@stdlib/ndarray-base-shape2strides": "^0.1.1", "@stdlib/ndarray-base-sub2ind": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From a18c1412d033b1b403f0d9eb59912ab84fc7ca6e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Nov 2023 14:27:34 +0000 Subject: [PATCH 065/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6256 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 a0eca41..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 979f673..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.1.1-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0kF2V,FD",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r,LK","mode"))}else r.mode=[r.mode];for(s=0;sn+1){if(a=p(m,arguments[f=j-1]))throw a}else f=j;if(f-(h=1)!==n)throw new RangeError(d("0kF5p,LI",n,f-h));for((i=new Array(n+4))[0]=o,i[1]=s(o,m.order),i[2]=0;h ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p,LI', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,WAAYJ,IAE3C,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,WAAY,cAF1CL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,WAAY,OAAQL,EAAKO,KAAML,IAG/D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,WAAY,QAASL,EAAKW,QAGnD,IACR,CCfA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,WAAYS,IAS1C,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,WAAYU,EAAOI,EAAEjB,IAMpD,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,EAAGmB,UAAWnB,KAExDc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cc303fa..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From cebe0f9315bb9163465ff97e2fff6327eb85a9ff Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 2 Nov 2023 14:31:11 +0000 Subject: [PATCH 066/108] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 482 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 45 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 117 - lib/validate.js | 84 - package.json | 66 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 536 -- test/test.validate.js | 186 - 48 files changed, 6202 insertions(+), 5242 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 247ed00..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T03:01:47.514Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 5cd5c02..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6e1404c..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: '19 19 * * 2' - - # 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 + + ```
@@ -237,7 +230,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -299,11 +292,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 6e5aaee..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,482 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 644ccea..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/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 f14e96a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sub2ind from '../docs/types/index'; -export = sub2ind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a32fda4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var m=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var g=m(function(k,h){h.exports={mode:["throw"],order:"row-major"}});var p=m(function(F,f){ -var q=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),y=require('@stdlib/assert-is-array/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),O=require('@stdlib/ndarray-base-assert-is-index-mode/dist'),d=require('@stdlib/error-tools-fmtprodmsg/dist');function T(e,r){var i;if(!q(r))return new TypeError(d('0kF2V',r));if(l(r,"mode")){if(e.mode=r.mode,!y(e.mode))e.mode=[e.mode];else if(e.mode.length===0)return new TypeError(d('0kF5r',"mode"));for(i=0;ii+1){if(o=u-1,e=arguments[o],s=N(t,e),s)throw s}else o=u;if(n=1,o-n!==i)throw new RangeError(v('0kF5p',i,o-n));for(a=new Array(i+4),a[0]=r,a[1]=A(r,t.order),a[2]=0;n ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,CAAE,OAAQ,EAClB,MAAS,WACV,ICHA,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAU,QAAS,sCAAuC,EAC1DC,EAAc,QAAS,2CAA4C,EACnEC,EAAS,QAAS,uBAAwB,EA0B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,IAAI,EACJ,GAAK,CAACR,EAAUQ,CAAQ,EACvB,OAAO,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE/G,GAAKP,EAAYO,EAAS,MAAO,EAAI,CAEpC,GADAD,EAAK,KAAOC,EAAQ,KACf,CAACN,EAASK,EAAK,IAAK,EACxBA,EAAK,KAAO,CAAEA,EAAK,IAAK,UACbA,EAAK,KAAK,SAAW,EAChC,OAAO,IAAI,UAAWF,EAAQ,wDAAyD,MAAO,CAAE,EAEjG,IAAM,EAAI,EAAG,EAAIE,EAAK,KAAK,OAAQ,IAClC,GAAK,CAACH,EAAaG,EAAK,KAAM,CAAE,CAAE,EACjC,OAAO,IAAI,UAAWF,EAAQ,iFAAkF,OAAQE,EAAK,KAAM,CAAE,CAAE,CAAE,CAG5I,CACA,OAAKN,EAAYO,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACL,EAASI,EAAK,KAAM,GAClB,IAAI,UAAWF,EAAQ,kFAAmF,QAASE,EAAK,KAAM,CAAE,EAGlI,IACR,CAKAR,EAAO,QAAUO,ICnFjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAW,QAAS,8BAA+B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IAmCf,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAP,EAAQ,UAAW,CAAE,EAChB,CAACT,EAA2BS,CAAM,EACtC,MAAM,IAAI,UAAWL,EAAQ,8GAA+GK,CAAM,CAAE,EASrJ,GAPAK,EAAM,UAAU,OAChBJ,EAAQD,EAAM,OAEdG,EAAO,CAAC,EACRA,EAAK,KAAOP,EAAS,KAAK,MAAM,EAChCO,EAAK,MAAQP,EAAS,MAEjBS,EAAMJ,EAAM,GAIhB,GAHAM,EAAIF,EAAM,EACVN,EAAU,UAAWQ,CAAE,EACvBH,EAAMP,EAAUM,EAAMJ,CAAQ,EACzBK,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GADAC,EAAI,EACCC,EAAED,IAAML,EACZ,MAAM,IAAI,WAAYN,EAAQ,gIAAiIM,EAAOM,EAAED,CAAE,CAAE,EAM7K,IAJAJ,EAAO,IAAI,MAAOD,EAAM,CAAE,EAC1BC,EAAM,CAAE,EAAIF,EACZE,EAAM,CAAE,EAAIT,EAAeO,EAAOG,EAAK,KAAM,EAC7CD,EAAM,CAAE,EAAI,EACJI,EAAIC,EAAGD,IAAM,CACpB,GAAK,CAACd,EAAW,UAAWc,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oFAAqFW,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEvIJ,EAAMI,EAAE,CAAE,EAAI,UAAWA,CAAE,CAC5B,CACA,OAAAJ,EAAMI,EAAE,CAAE,EAAIH,EAAK,KACZT,EAAS,MAAO,KAAMQ,CAAK,CACnC,CAKAZ,EAAO,QAAUQ,IClFjB,IAAIU,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isArray", "isOrder", "isIndexMode", "format", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeIntegerArray", "isInteger", "shape2strides", "getIndex", "format", "defaults", "validate", "sub2ind", "options", "shape", "ndims", "args", "opts", "err", "len", "i", "j", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index bf46b8d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'wrap', the function wraps around - subscripts exceeding array dimensions using modulo arithmetic. If equal - to 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 1d6c0b9..a0eca41 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..979f673 --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.1.1-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0kF2V,FD",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r,LK","mode"))}else r.mode=[r.mode];for(s=0;sn+1){if(a=p(m,arguments[f=j-1]))throw a}else f=j;if(f-(h=1)!==n)throw new RangeError(d("0kF5p,LI",n,f-h));for((i=new Array(n+4))[0]=o,i[1]=s(o,m.order),i[2]=0;h ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p,LI', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,WAAYJ,IAE3C,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,WAAY,cAF1CL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,WAAY,OAAQL,EAAKO,KAAML,IAG/D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,WAAY,QAASL,EAAKW,QAGnD,IACR,CCfA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,WAAYS,IAS1C,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,WAAYU,EAAOI,EAAEjB,IAMpD,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,EAAGmB,UAAWnB,KAExDc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 94a70a8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0kF5o,LH', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( '0kF5p,LI', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0d5fc73..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0kF2V,FD', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0kF5r,LK', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0kF5m,LL', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0kF5n,LM', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 2b503f9..a0c93a6 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@stdlib/ndarray-base-shape2strides": "^0.1.1", - "@stdlib/ndarray-base-sub2ind": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/bench": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/random-base-discrete-uniform": "^0.1.0", - "@stdlib/random-base-randu": "^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", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1852f56 --- /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 3b0c7e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,536 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index c03e1cc..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From c653bfadb6ec62d1627d18d472b22aa6b40d3918 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 Nov 2023 07:30:22 +0000 Subject: [PATCH 067/108] Transform error messages --- lib/main.js | 8 ++++---- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/main.js b/lib/main.js index 08e2c51..b416546 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0kF5o,LH', shape ) ); } len = arguments.length; ndims = shape.length; @@ -96,7 +96,7 @@ function sub2ind() { } i = 1; if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); + throw new RangeError( format( '0kF5p,LI', ndims, j-i ) ); } args = new Array( ndims+4 ); args[ 0 ] = shape; @@ -104,7 +104,7 @@ function sub2ind() { args[ 2 ] = 0; // strides are positive, so offset is always zero for ( ; i < j; i++ ) { if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); + throw new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) ); } args[ i+2 ] = arguments[ i ]; } diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..0d5fc73 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0kF2V,FD', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0kF5r,LK', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0kF5m,LL', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0kF5n,LM', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 7a3acac..b2454db 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.1.1", "@stdlib/ndarray-base-shape2strides": "^0.1.1", "@stdlib/ndarray-base-sub2ind": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 54863637cf83e8a8e54c9a1265a4c22da05cbfe7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 Nov 2023 07:30:58 +0000 Subject: [PATCH 068/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6256 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 a0eca41..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - `throw`: throws an error when a subscript exceeds array dimensions. -* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 979f673..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.1.1-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0kF2V,FD",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r,LK","mode"))}else r.mode=[r.mode];for(s=0;sn+1){if(a=p(m,arguments[f=j-1]))throw a}else f=j;if(f-(h=1)!==n)throw new RangeError(d("0kF5p,LI",n,f-h));for((i=new Array(n+4))[0]=o,i[1]=s(o,m.order),i[2]=0;h ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p,LI', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,WAAYJ,IAE3C,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,WAAY,cAF1CL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,WAAY,OAAQL,EAAKO,KAAML,IAG/D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,WAAY,QAASL,EAAKW,QAGnD,IACR,CCfA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,WAAYS,IAS1C,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,WAAYU,EAAOI,EAAEjB,IAMpD,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,EAAGmB,UAAWnB,KAExDc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1852f56..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8e8178918d207925cb109e3249dca85103ae7192 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 Nov 2023 07:33:31 +0000 Subject: [PATCH 069/108] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 552 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 588 -- test/test.validate.js | 186 - 47 files changed, 6202 insertions(+), 5361 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 5cd5c02..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6e1404c..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: '19 19 * * 2' - - # 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 + + ```
@@ -238,7 +231,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -300,11 +293,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 161cce2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,552 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=normalize', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'normalize' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[normalize]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'normalize' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 644ccea..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/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 f14e96a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sub2ind from '../docs/types/index'; -export = sub2ind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a32fda4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var m=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var g=m(function(k,h){h.exports={mode:["throw"],order:"row-major"}});var p=m(function(F,f){ -var q=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),y=require('@stdlib/assert-is-array/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),O=require('@stdlib/ndarray-base-assert-is-index-mode/dist'),d=require('@stdlib/error-tools-fmtprodmsg/dist');function T(e,r){var i;if(!q(r))return new TypeError(d('0kF2V',r));if(l(r,"mode")){if(e.mode=r.mode,!y(e.mode))e.mode=[e.mode];else if(e.mode.length===0)return new TypeError(d('0kF5r',"mode"));for(i=0;ii+1){if(o=u-1,e=arguments[o],s=N(t,e),s)throw s}else o=u;if(n=1,o-n!==i)throw new RangeError(v('0kF5p',i,o-n));for(a=new Array(i+4),a[0]=r,a[1]=A(r,t.order),a[2]=0;n ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,CAAE,OAAQ,EAClB,MAAS,WACV,ICHA,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAU,QAAS,sCAAuC,EAC1DC,EAAc,QAAS,2CAA4C,EACnEC,EAAS,QAAS,uBAAwB,EA0B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,IAAI,EACJ,GAAK,CAACR,EAAUQ,CAAQ,EACvB,OAAO,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE/G,GAAKP,EAAYO,EAAS,MAAO,EAAI,CAEpC,GADAD,EAAK,KAAOC,EAAQ,KACf,CAACN,EAASK,EAAK,IAAK,EACxBA,EAAK,KAAO,CAAEA,EAAK,IAAK,UACbA,EAAK,KAAK,SAAW,EAChC,OAAO,IAAI,UAAWF,EAAQ,wDAAyD,MAAO,CAAE,EAEjG,IAAM,EAAI,EAAG,EAAIE,EAAK,KAAK,OAAQ,IAClC,GAAK,CAACH,EAAaG,EAAK,KAAM,CAAE,CAAE,EACjC,OAAO,IAAI,UAAWF,EAAQ,iFAAkF,OAAQE,EAAK,KAAM,CAAE,CAAE,CAAE,CAG5I,CACA,OAAKN,EAAYO,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACL,EAASI,EAAK,KAAM,GAClB,IAAI,UAAWF,EAAQ,kFAAmF,QAASE,EAAK,KAAM,CAAE,EAGlI,IACR,CAKAR,EAAO,QAAUO,ICnFjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAW,QAAS,8BAA+B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IAoCf,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAP,EAAQ,UAAW,CAAE,EAChB,CAACT,EAA2BS,CAAM,EACtC,MAAM,IAAI,UAAWL,EAAQ,8GAA+GK,CAAM,CAAE,EASrJ,GAPAK,EAAM,UAAU,OAChBJ,EAAQD,EAAM,OAEdG,EAAO,CAAC,EACRA,EAAK,KAAOP,EAAS,KAAK,MAAM,EAChCO,EAAK,MAAQP,EAAS,MAEjBS,EAAMJ,EAAM,GAIhB,GAHAM,EAAIF,EAAM,EACVN,EAAU,UAAWQ,CAAE,EACvBH,EAAMP,EAAUM,EAAMJ,CAAQ,EACzBK,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GADAC,EAAI,EACCC,EAAED,IAAML,EACZ,MAAM,IAAI,WAAYN,EAAQ,gIAAiIM,EAAOM,EAAED,CAAE,CAAE,EAM7K,IAJAJ,EAAO,IAAI,MAAOD,EAAM,CAAE,EAC1BC,EAAM,CAAE,EAAIF,EACZE,EAAM,CAAE,EAAIT,EAAeO,EAAOG,EAAK,KAAM,EAC7CD,EAAM,CAAE,EAAI,EACJI,EAAIC,EAAGD,IAAM,CACpB,GAAK,CAACd,EAAW,UAAWc,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oFAAqFW,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEvIJ,EAAMI,EAAE,CAAE,EAAI,UAAWA,CAAE,CAC5B,CACA,OAAAJ,EAAMI,EAAE,CAAE,EAAIH,EAAK,KACZT,EAAS,MAAO,KAAMQ,CAAK,CACnC,CAKAZ,EAAO,QAAUQ,ICnFjB,IAAIU,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isArray", "isOrder", "isIndexMode", "format", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeIntegerArray", "isInteger", "shape2strides", "getIndex", "format", "defaults", "validate", "sub2ind", "options", "shape", "ndims", "args", "opts", "err", "len", "i", "j", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 837a6bc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'normalize', the function normalizes - negative subscripts and throws an error when a subscript exceeds array - dimensions. If equal to 'wrap', the function wraps around subscripts - exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 28bf1e4..7482e78 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..979f673 --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.1.1-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0kF2V,FD",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r,LK","mode"))}else r.mode=[r.mode];for(s=0;sn+1){if(a=p(m,arguments[f=j-1]))throw a}else f=j;if(f-(h=1)!==n)throw new RangeError(d("0kF5p,LI",n,f-h));for((i=new Array(n+4))[0]=o,i[1]=s(o,m.order),i[2]=0;h ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p,LI', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,WAAYJ,IAE3C,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,WAAY,cAF1CL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,WAAY,OAAQL,EAAKO,KAAML,IAG/D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,WAAY,QAASL,EAAKW,QAGnD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,WAAYS,IAS1C,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,WAAYU,EAAOI,EAAEjB,IAMpD,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,EAAGmB,UAAWnB,KAExDc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index b416546..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0kF5o,LH', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( '0kF5p,LI', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0d5fc73..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0kF2V,FD', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0kF5r,LK', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0kF5m,LL', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0kF5n,LM', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index b2454db..a0c93a6 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@stdlib/ndarray-base-shape2strides": "^0.1.1", - "@stdlib/ndarray-base-sub2ind": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/bench": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/random-base-discrete-uniform": "^0.1.0", - "@stdlib/random-base-randu": "^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", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4a04296 --- /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 c44bc30..0000000 --- a/test/test.js +++ /dev/null @@ -1,588 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'normalizes', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'normalize', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, -999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, -1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -2, -2, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, -1, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index a501cdf..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw', 'normalize' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 3d868a14d40dc5901e63eb5a97eedf0466d039d3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 14:05:38 +0000 Subject: [PATCH 070/108] Transform error messages --- lib/main.js | 8 ++++---- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/main.js b/lib/main.js index 08e2c51..b416546 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0kF5o,LH', shape ) ); } len = arguments.length; ndims = shape.length; @@ -96,7 +96,7 @@ function sub2ind() { } i = 1; if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); + throw new RangeError( format( '0kF5p,LI', ndims, j-i ) ); } args = new Array( ndims+4 ); args[ 0 ] = shape; @@ -104,7 +104,7 @@ function sub2ind() { args[ 2 ] = 0; // strides are positive, so offset is always zero for ( ; i < j; i++ ) { if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); + throw new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) ); } args[ i+2 ] = arguments[ i ]; } diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..0d5fc73 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0kF2V,FD', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0kF5r,LK', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0kF5m,LL', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0kF5n,LM', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 7a3acac..b2454db 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.1.1", "@stdlib/ndarray-base-shape2strides": "^0.1.1", "@stdlib/ndarray-base-sub2ind": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From ed45bd19c26d300dad8aa3502226d594c45565ae Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 12:27:16 +0000 Subject: [PATCH 071/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6256 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 7482e78..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 979f673..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.1.1-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0kF2V,FD",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r,LK","mode"))}else r.mode=[r.mode];for(s=0;sn+1){if(a=p(m,arguments[f=j-1]))throw a}else f=j;if(f-(h=1)!==n)throw new RangeError(d("0kF5p,LI",n,f-h));for((i=new Array(n+4))[0]=o,i[1]=s(o,m.order),i[2]=0;h ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p,LI', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,WAAYJ,IAE3C,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,WAAY,cAF1CL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,WAAY,OAAQL,EAAKO,KAAML,IAG/D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,WAAY,QAASL,EAAKW,QAGnD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,WAAYS,IAS1C,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,WAAYU,EAAOI,EAAEjB,IAMpD,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,EAAGmB,UAAWnB,KAExDc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4a04296..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 86ecc470b34c6fbdd28f881b1cf7cb3a7bcc017d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 12:29:41 +0000 Subject: [PATCH 072/108] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 41 +- benchmark/benchmark.js | 552 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 588 -- test/test.validate.js | 186 - 48 files changed, 6202 insertions(+), 5362 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 cbfb60b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T05:57:12.849Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 5cd5c02..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 6e1404c..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: '19 19 * * 2' - - # 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 + + ```
@@ -238,7 +231,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -300,11 +293,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 161cce2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,552 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=normalize', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'normalize' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[normalize]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'normalize' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 644ccea..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/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 f14e96a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sub2ind from '../docs/types/index'; -export = sub2ind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a32fda4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var m=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var g=m(function(k,h){h.exports={mode:["throw"],order:"row-major"}});var p=m(function(F,f){ -var q=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),y=require('@stdlib/assert-is-array/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),O=require('@stdlib/ndarray-base-assert-is-index-mode/dist'),d=require('@stdlib/error-tools-fmtprodmsg/dist');function T(e,r){var i;if(!q(r))return new TypeError(d('0kF2V',r));if(l(r,"mode")){if(e.mode=r.mode,!y(e.mode))e.mode=[e.mode];else if(e.mode.length===0)return new TypeError(d('0kF5r',"mode"));for(i=0;ii+1){if(o=u-1,e=arguments[o],s=N(t,e),s)throw s}else o=u;if(n=1,o-n!==i)throw new RangeError(v('0kF5p',i,o-n));for(a=new Array(i+4),a[0]=r,a[1]=A(r,t.order),a[2]=0;n ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,CAAE,OAAQ,EAClB,MAAS,WACV,ICHA,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAU,QAAS,sCAAuC,EAC1DC,EAAc,QAAS,2CAA4C,EACnEC,EAAS,QAAS,uBAAwB,EA0B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,IAAI,EACJ,GAAK,CAACR,EAAUQ,CAAQ,EACvB,OAAO,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE/G,GAAKP,EAAYO,EAAS,MAAO,EAAI,CAEpC,GADAD,EAAK,KAAOC,EAAQ,KACf,CAACN,EAASK,EAAK,IAAK,EACxBA,EAAK,KAAO,CAAEA,EAAK,IAAK,UACbA,EAAK,KAAK,SAAW,EAChC,OAAO,IAAI,UAAWF,EAAQ,wDAAyD,MAAO,CAAE,EAEjG,IAAM,EAAI,EAAG,EAAIE,EAAK,KAAK,OAAQ,IAClC,GAAK,CAACH,EAAaG,EAAK,KAAM,CAAE,CAAE,EACjC,OAAO,IAAI,UAAWF,EAAQ,iFAAkF,OAAQE,EAAK,KAAM,CAAE,CAAE,CAAE,CAG5I,CACA,OAAKN,EAAYO,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACL,EAASI,EAAK,KAAM,GAClB,IAAI,UAAWF,EAAQ,kFAAmF,QAASE,EAAK,KAAM,CAAE,EAGlI,IACR,CAKAR,EAAO,QAAUO,ICnFjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAW,QAAS,8BAA+B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IAoCf,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAP,EAAQ,UAAW,CAAE,EAChB,CAACT,EAA2BS,CAAM,EACtC,MAAM,IAAI,UAAWL,EAAQ,8GAA+GK,CAAM,CAAE,EASrJ,GAPAK,EAAM,UAAU,OAChBJ,EAAQD,EAAM,OAEdG,EAAO,CAAC,EACRA,EAAK,KAAOP,EAAS,KAAK,MAAM,EAChCO,EAAK,MAAQP,EAAS,MAEjBS,EAAMJ,EAAM,GAIhB,GAHAM,EAAIF,EAAM,EACVN,EAAU,UAAWQ,CAAE,EACvBH,EAAMP,EAAUM,EAAMJ,CAAQ,EACzBK,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GADAC,EAAI,EACCC,EAAED,IAAML,EACZ,MAAM,IAAI,WAAYN,EAAQ,gIAAiIM,EAAOM,EAAED,CAAE,CAAE,EAM7K,IAJAJ,EAAO,IAAI,MAAOD,EAAM,CAAE,EAC1BC,EAAM,CAAE,EAAIF,EACZE,EAAM,CAAE,EAAIT,EAAeO,EAAOG,EAAK,KAAM,EAC7CD,EAAM,CAAE,EAAI,EACJI,EAAIC,EAAGD,IAAM,CACpB,GAAK,CAACd,EAAW,UAAWc,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oFAAqFW,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEvIJ,EAAMI,EAAE,CAAE,EAAI,UAAWA,CAAE,CAC5B,CACA,OAAAJ,EAAMI,EAAE,CAAE,EAAIH,EAAK,KACZT,EAAS,MAAO,KAAMQ,CAAK,CACnC,CAKAZ,EAAO,QAAUQ,ICnFjB,IAAIU,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isArray", "isOrder", "isIndexMode", "format", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeIntegerArray", "isInteger", "shape2strides", "getIndex", "format", "defaults", "validate", "sub2ind", "options", "shape", "ndims", "args", "opts", "err", "len", "i", "j", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 837a6bc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'normalize', the function normalizes - negative subscripts and throws an error when a subscript exceeds array - dimensions. If equal to 'wrap', the function wraps around subscripts - exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 28bf1e4..7482e78 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..979f673 --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.1.1-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0kF2V,FD",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r,LK","mode"))}else r.mode=[r.mode];for(s=0;sn+1){if(a=p(m,arguments[f=j-1]))throw a}else f=j;if(f-(h=1)!==n)throw new RangeError(d("0kF5p,LI",n,f-h));for((i=new Array(n+4))[0]=o,i[1]=s(o,m.order),i[2]=0;h ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p,LI', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,WAAYJ,IAE3C,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,WAAY,cAF1CL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,WAAY,OAAQL,EAAKO,KAAML,IAG/D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,WAAY,QAASL,EAAKW,QAGnD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,WAAYS,IAS1C,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,WAAYU,EAAOI,EAAEjB,IAMpD,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,EAAGmB,UAAWnB,KAExDc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index b416546..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0kF5o,LH', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( '0kF5p,LI', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 0d5fc73..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0kF2V,FD', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0kF5r,LK', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0kF5m,LL', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0kF5n,LM', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index b2454db..a0c93a6 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@stdlib/ndarray-base-shape2strides": "^0.1.1", - "@stdlib/ndarray-base-sub2ind": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/bench": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/random-base-discrete-uniform": "^0.1.0", - "@stdlib/random-base-randu": "^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", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6301266 --- /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 c44bc30..0000000 --- a/test/test.js +++ /dev/null @@ -1,588 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'normalizes', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'normalize', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, -999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, -1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -2, -2, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, -1, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index a501cdf..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw', 'normalize' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From e6211d94493c67e6f81d38da98b9d2c58eda8195 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 08:27:01 +0000 Subject: [PATCH 073/108] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8d32f7f..702f43a 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.1.1", "@stdlib/ndarray-base-shape2strides": "^0.1.1", "@stdlib/ndarray-base-sub2ind": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 754d0f3e35adbe574869ae1b17939b167e2b988a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 15:02:50 +0000 Subject: [PATCH 074/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6256 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 7482e78..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 979f673..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.1.0-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.1.1-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(r,e){var s;if(!o(e))return new TypeError(d("0kF2V,FD",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r,LK","mode"))}else r.mode=[r.mode];for(s=0;sn+1){if(a=p(m,arguments[f=j-1]))throw a}else f=j;if(f-(h=1)!==n)throw new RangeError(d("0kF5p,LI",n,f-h));for((i=new Array(n+4))[0]=o,i[1]=s(o,m.order),i[2]=0;h ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p,LI', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q,LJ', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,WAAYJ,IAE3C,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,WAAY,cAF1CL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,WAAY,OAAQL,EAAKO,KAAML,IAG/D,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,WAAY,QAASL,EAAKW,QAGnD,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,WAAYS,IAS1C,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,WAAYU,EAAOI,EAAEjB,IAMpD,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,WAAYH,EAAGmB,UAAWnB,KAExDc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6301266..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 250575dfbbb5342cb7bb0c04195f0aaa5c285436 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 15:03:16 +0000 Subject: [PATCH 075/108] 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 | 41 +- SECURITY.md | 5 - benchmark/benchmark.js | 552 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 588 -- test/test.validate.js | 186 - 49 files changed, 6202 insertions(+), 5368 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 a664818..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:27:06.816Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 5cd5c02..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 16d5605..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: '19 19 * * 2' - - # 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 + + ```
@@ -238,7 +231,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -300,11 +293,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/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 7268bb4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,552 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=normalize', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'normalize' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[normalize]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'normalize' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 644ccea..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/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 f14e96a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sub2ind from '../docs/types/index'; -export = sub2ind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a32fda4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var m=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var g=m(function(k,h){h.exports={mode:["throw"],order:"row-major"}});var p=m(function(F,f){ -var q=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),y=require('@stdlib/assert-is-array/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),O=require('@stdlib/ndarray-base-assert-is-index-mode/dist'),d=require('@stdlib/error-tools-fmtprodmsg/dist');function T(e,r){var i;if(!q(r))return new TypeError(d('0kF2V',r));if(l(r,"mode")){if(e.mode=r.mode,!y(e.mode))e.mode=[e.mode];else if(e.mode.length===0)return new TypeError(d('0kF5r',"mode"));for(i=0;ii+1){if(o=u-1,e=arguments[o],s=N(t,e),s)throw s}else o=u;if(n=1,o-n!==i)throw new RangeError(v('0kF5p',i,o-n));for(a=new Array(i+4),a[0]=r,a[1]=A(r,t.order),a[2]=0;n ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,CAAE,OAAQ,EAClB,MAAS,WACV,ICHA,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAU,QAAS,sCAAuC,EAC1DC,EAAc,QAAS,2CAA4C,EACnEC,EAAS,QAAS,uBAAwB,EA0B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,IAAI,EACJ,GAAK,CAACR,EAAUQ,CAAQ,EACvB,OAAO,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE/G,GAAKP,EAAYO,EAAS,MAAO,EAAI,CAEpC,GADAD,EAAK,KAAOC,EAAQ,KACf,CAACN,EAASK,EAAK,IAAK,EACxBA,EAAK,KAAO,CAAEA,EAAK,IAAK,UACbA,EAAK,KAAK,SAAW,EAChC,OAAO,IAAI,UAAWF,EAAQ,wDAAyD,MAAO,CAAE,EAEjG,IAAM,EAAI,EAAG,EAAIE,EAAK,KAAK,OAAQ,IAClC,GAAK,CAACH,EAAaG,EAAK,KAAM,CAAE,CAAE,EACjC,OAAO,IAAI,UAAWF,EAAQ,iFAAkF,OAAQE,EAAK,KAAM,CAAE,CAAE,CAAE,CAG5I,CACA,OAAKN,EAAYO,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACL,EAASI,EAAK,KAAM,GAClB,IAAI,UAAWF,EAAQ,kFAAmF,QAASE,EAAK,KAAM,CAAE,EAGlI,IACR,CAKAR,EAAO,QAAUO,ICnFjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAW,QAAS,8BAA+B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IAoCf,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAP,EAAQ,UAAW,CAAE,EAChB,CAACT,EAA2BS,CAAM,EACtC,MAAM,IAAI,UAAWL,EAAQ,8GAA+GK,CAAM,CAAE,EASrJ,GAPAK,EAAM,UAAU,OAChBJ,EAAQD,EAAM,OAEdG,EAAO,CAAC,EACRA,EAAK,KAAOP,EAAS,KAAK,MAAM,EAChCO,EAAK,MAAQP,EAAS,MAEjBS,EAAMJ,EAAM,GAIhB,GAHAM,EAAIF,EAAM,EACVN,EAAU,UAAWQ,CAAE,EACvBH,EAAMP,EAAUM,EAAMJ,CAAQ,EACzBK,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GADAC,EAAI,EACCC,EAAED,IAAML,EACZ,MAAM,IAAI,WAAYN,EAAQ,gIAAiIM,EAAOM,EAAED,CAAE,CAAE,EAM7K,IAJAJ,EAAO,IAAI,MAAOD,EAAM,CAAE,EAC1BC,EAAM,CAAE,EAAIF,EACZE,EAAM,CAAE,EAAIT,EAAeO,EAAOG,EAAK,KAAM,EAC7CD,EAAM,CAAE,EAAI,EACJI,EAAIC,EAAGD,IAAM,CACpB,GAAK,CAACd,EAAW,UAAWc,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oFAAqFW,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEvIJ,EAAMI,EAAE,CAAE,EAAI,UAAWA,CAAE,CAC5B,CACA,OAAAJ,EAAMI,EAAE,CAAE,EAAIH,EAAK,KACZT,EAAS,MAAO,KAAMQ,CAAK,CACnC,CAKAZ,EAAO,QAAUQ,ICnFjB,IAAIU,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isArray", "isOrder", "isIndexMode", "format", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeIntegerArray", "isInteger", "shape2strides", "getIndex", "format", "defaults", "validate", "sub2ind", "options", "shape", "ndims", "args", "opts", "err", "len", "i", "j", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 837a6bc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'normalize', the function normalizes - negative subscripts and throws an error when a subscript exceeds array - dimensions. If equal to 'wrap', the function wraps around subscripts - exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 28bf1e4..7482e78 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..172a869 --- /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{primitives as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.1.1-esm/index.mjs";var p={mode:["throw"],order:"row-major"};function l(e,r){var s;if(!i(r))return new TypeError(n("invalid argument. Options argument must be an object. Value: `%s`.",r));if(o(r,"mode")){if(e.mode=r.mode,d(e.mode)){if(0===e.mode.length)return new TypeError(n("invalid option. `%s` option cannot be an empty array.","mode"))}else e.mode=[e.mode];for(s=0;so+1){if(a=l(m,arguments[v=u-1]))throw a}else v=u;if(v-(j=1)!==o)throw new RangeError(n("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",o,v-j));for((d=new Array(o+4))[0]=i,d[1]=s(i,m.order),d[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;4hCAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,qEAAsEJ,IAErG,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,wDAAyD,cAFvFL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,iFAAkF,OAAQL,EAAKO,KAAML,IAGrI,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,kFAAmF,QAASL,EAAKW,QAG1H,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,8GAA+GS,IAS7I,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 08e2c51..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 5795b2b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 702f43a..a0c93a6 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@stdlib/ndarray-base-shape2strides": "^0.1.1", - "@stdlib/ndarray-base-sub2ind": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/random-base-discrete-uniform": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b05db67 --- /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 c44bc30..0000000 --- a/test/test.js +++ /dev/null @@ -1,588 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'normalizes', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'normalize', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, -999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, -1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -2, -2, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, -1, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index a501cdf..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw', 'normalize' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From b7f24ce94d1518c2f80f95e7232c0f62237205fe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 09:04:30 +0000 Subject: [PATCH 076/108] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8d32f7f..702f43a 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.1.1", "@stdlib/ndarray-base-shape2strides": "^0.1.1", "@stdlib/ndarray-base-sub2ind": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From ed7ad8484f95ac2fc7484bb172f3183b875eef6b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 14:27:18 +0000 Subject: [PATCH 077/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6256 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 7482e78..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 172a869..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{primitives as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.1.1-esm/index.mjs";var p={mode:["throw"],order:"row-major"};function l(e,r){var s;if(!i(r))return new TypeError(n("invalid argument. Options argument must be an object. Value: `%s`.",r));if(o(r,"mode")){if(e.mode=r.mode,d(e.mode)){if(0===e.mode.length)return new TypeError(n("invalid option. `%s` option cannot be an empty array.","mode"))}else e.mode=[e.mode];for(s=0;so+1){if(a=l(m,arguments[v=u-1]))throw a}else v=u;if(v-(j=1)!==o)throw new RangeError(n("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",o,v-j));for((d=new Array(o+4))[0]=i,d[1]=s(i,m.order),d[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;4hCAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,qEAAsEJ,IAErG,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,wDAAyD,cAFvFL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,iFAAkF,OAAQL,EAAKO,KAAML,IAGrI,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,kFAAmF,QAASL,EAAKW,QAG1H,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,8GAA+GS,IAS7I,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b05db67..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e3eab538faff9ba0314ab2480e6d525ca1ad769e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 14:27:44 +0000 Subject: [PATCH 078/108] 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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 552 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 588 -- test/test.validate.js | 186 - 49 files changed, 6202 insertions(+), 5373 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 2c03206..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T06:21:31.455Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 5cd5c02..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 16d5605..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: '19 19 * * 2' - - # 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 + + ```
@@ -240,7 +231,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -305,11 +296,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/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 7268bb4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,552 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=normalize', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'normalize' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[normalize]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'normalize' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5065893..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-sub2ind/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 f14e96a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sub2ind from '../docs/types/index'; -export = sub2ind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a32fda4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var m=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var g=m(function(k,h){h.exports={mode:["throw"],order:"row-major"}});var p=m(function(F,f){ -var q=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),y=require('@stdlib/assert-is-array/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),O=require('@stdlib/ndarray-base-assert-is-index-mode/dist'),d=require('@stdlib/error-tools-fmtprodmsg/dist');function T(e,r){var i;if(!q(r))return new TypeError(d('0kF2V',r));if(l(r,"mode")){if(e.mode=r.mode,!y(e.mode))e.mode=[e.mode];else if(e.mode.length===0)return new TypeError(d('0kF5r',"mode"));for(i=0;ii+1){if(o=u-1,e=arguments[o],s=N(t,e),s)throw s}else o=u;if(n=1,o-n!==i)throw new RangeError(v('0kF5p',i,o-n));for(a=new Array(i+4),a[0]=r,a[1]=A(r,t.order),a[2]=0;n ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,CAAE,OAAQ,EAClB,MAAS,WACV,ICHA,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAU,QAAS,sCAAuC,EAC1DC,EAAc,QAAS,2CAA4C,EACnEC,EAAS,QAAS,uBAAwB,EA0B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,IAAI,EACJ,GAAK,CAACR,EAAUQ,CAAQ,EACvB,OAAO,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE/G,GAAKP,EAAYO,EAAS,MAAO,EAAI,CAEpC,GADAD,EAAK,KAAOC,EAAQ,KACf,CAACN,EAASK,EAAK,IAAK,EACxBA,EAAK,KAAO,CAAEA,EAAK,IAAK,UACbA,EAAK,KAAK,SAAW,EAChC,OAAO,IAAI,UAAWF,EAAQ,wDAAyD,MAAO,CAAE,EAEjG,IAAM,EAAI,EAAG,EAAIE,EAAK,KAAK,OAAQ,IAClC,GAAK,CAACH,EAAaG,EAAK,KAAM,CAAE,CAAE,EACjC,OAAO,IAAI,UAAWF,EAAQ,iFAAkF,OAAQE,EAAK,KAAM,CAAE,CAAE,CAAE,CAG5I,CACA,OAAKN,EAAYO,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACL,EAASI,EAAK,KAAM,GAClB,IAAI,UAAWF,EAAQ,kFAAmF,QAASE,EAAK,KAAM,CAAE,EAGlI,IACR,CAKAR,EAAO,QAAUO,ICnFjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAW,QAAS,8BAA+B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IAoCf,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAP,EAAQ,UAAW,CAAE,EAChB,CAACT,EAA2BS,CAAM,EACtC,MAAM,IAAI,UAAWL,EAAQ,8GAA+GK,CAAM,CAAE,EASrJ,GAPAK,EAAM,UAAU,OAChBJ,EAAQD,EAAM,OAEdG,EAAO,CAAC,EACRA,EAAK,KAAOP,EAAS,KAAK,MAAM,EAChCO,EAAK,MAAQP,EAAS,MAEjBS,EAAMJ,EAAM,GAIhB,GAHAM,EAAIF,EAAM,EACVN,EAAU,UAAWQ,CAAE,EACvBH,EAAMP,EAAUM,EAAMJ,CAAQ,EACzBK,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GADAC,EAAI,EACCC,EAAED,IAAML,EACZ,MAAM,IAAI,WAAYN,EAAQ,gIAAiIM,EAAOM,EAAED,CAAE,CAAE,EAM7K,IAJAJ,EAAO,IAAI,MAAOD,EAAM,CAAE,EAC1BC,EAAM,CAAE,EAAIF,EACZE,EAAM,CAAE,EAAIT,EAAeO,EAAOG,EAAK,KAAM,EAC7CD,EAAM,CAAE,EAAI,EACJI,EAAIC,EAAGD,IAAM,CACpB,GAAK,CAACd,EAAW,UAAWc,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oFAAqFW,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEvIJ,EAAMI,EAAE,CAAE,EAAI,UAAWA,CAAE,CAC5B,CACA,OAAAJ,EAAMI,EAAE,CAAE,EAAIH,EAAK,KACZT,EAAS,MAAO,KAAMQ,CAAK,CACnC,CAKAZ,EAAO,QAAUQ,ICnFjB,IAAIU,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isArray", "isOrder", "isIndexMode", "format", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeIntegerArray", "isInteger", "shape2strides", "getIndex", "format", "defaults", "validate", "sub2ind", "options", "shape", "ndims", "args", "opts", "err", "len", "i", "j", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 837a6bc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'normalize', the function normalizes - negative subscripts and throws an error when a subscript exceeds array - dimensions. If equal to 'wrap', the function wraps around subscripts - exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 28bf1e4..7482e78 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..172a869 --- /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{primitives as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.1.1-esm/index.mjs";var p={mode:["throw"],order:"row-major"};function l(e,r){var s;if(!i(r))return new TypeError(n("invalid argument. Options argument must be an object. Value: `%s`.",r));if(o(r,"mode")){if(e.mode=r.mode,d(e.mode)){if(0===e.mode.length)return new TypeError(n("invalid option. `%s` option cannot be an empty array.","mode"))}else e.mode=[e.mode];for(s=0;so+1){if(a=l(m,arguments[v=u-1]))throw a}else v=u;if(v-(j=1)!==o)throw new RangeError(n("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",o,v-j));for((d=new Array(o+4))[0]=i,d[1]=s(i,m.order),d[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;4hCAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,qEAAsEJ,IAErG,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,wDAAyD,cAFvFL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,iFAAkF,OAAQL,EAAKO,KAAML,IAGrI,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,kFAAmF,QAASL,EAAKW,QAG1H,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,8GAA+GS,IAS7I,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 08e2c51..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 5795b2b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 702f43a..a0c93a6 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer-array": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.1.1", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@stdlib/ndarray-base-shape2strides": "^0.1.1", - "@stdlib/ndarray-base-sub2ind": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/random-base-discrete-uniform": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..89e37a6 --- /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 c44bc30..0000000 --- a/test/test.js +++ /dev/null @@ -1,588 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'normalizes', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'normalize', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, -999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, -1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -2, -2, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, -1, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index a501cdf..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw', 'normalize' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From f32aa7c91970b70932c6c5d5f51e6b937d095f03 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 01:11:59 +0000 Subject: [PATCH 079/108] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b1a9495..cddeb58 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.2.0", "@stdlib/ndarray-base-shape2strides": "^0.2.0", "@stdlib/ndarray-base-sub2ind": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1" }, "devDependencies": { From ba8818037edaa26b164a42e67113e20a1f860df5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:38:48 +0000 Subject: [PATCH 080/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6256 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 7482e78..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 172a869..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{primitives as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.1.1-esm/index.mjs";var p={mode:["throw"],order:"row-major"};function l(e,r){var s;if(!i(r))return new TypeError(n("invalid argument. Options argument must be an object. Value: `%s`.",r));if(o(r,"mode")){if(e.mode=r.mode,d(e.mode)){if(0===e.mode.length)return new TypeError(n("invalid option. `%s` option cannot be an empty array.","mode"))}else e.mode=[e.mode];for(s=0;so+1){if(a=l(m,arguments[v=u-1]))throw a}else v=u;if(v-(j=1)!==o)throw new RangeError(n("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",o,v-j));for((d=new Array(o+4))[0]=i,d[1]=s(i,m.order),d[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;4hCAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,qEAAsEJ,IAErG,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,wDAAyD,cAFvFL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,iFAAkF,OAAQL,EAAKO,KAAML,IAGrI,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,kFAAmF,QAASL,EAAKW,QAG1H,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,8GAA+GS,IAS7I,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 89e37a6..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f3eabd9371a27ddde3e57eecfddec1930d5f85ac Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:40:07 +0000 Subject: [PATCH 081/108] 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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 552 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 66 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 588 -- test/test.validate.js | 186 - 48 files changed, 6202 insertions(+), 5376 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 5cd5c02..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 ed0f2d6..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: '19 19 * * 2' - - # 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 + + ```
@@ -240,7 +231,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -305,11 +296,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/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 7268bb4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,552 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=normalize', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'normalize' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[normalize]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'normalize' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5065893..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-sub2ind/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 f14e96a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sub2ind from '../docs/types/index'; -export = sub2ind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a32fda4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var m=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var g=m(function(k,h){h.exports={mode:["throw"],order:"row-major"}});var p=m(function(F,f){ -var q=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),y=require('@stdlib/assert-is-array/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),O=require('@stdlib/ndarray-base-assert-is-index-mode/dist'),d=require('@stdlib/error-tools-fmtprodmsg/dist');function T(e,r){var i;if(!q(r))return new TypeError(d('0kF2V',r));if(l(r,"mode")){if(e.mode=r.mode,!y(e.mode))e.mode=[e.mode];else if(e.mode.length===0)return new TypeError(d('0kF5r',"mode"));for(i=0;ii+1){if(o=u-1,e=arguments[o],s=N(t,e),s)throw s}else o=u;if(n=1,o-n!==i)throw new RangeError(v('0kF5p',i,o-n));for(a=new Array(i+4),a[0]=r,a[1]=A(r,t.order),a[2]=0;n ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,CAAE,OAAQ,EAClB,MAAS,WACV,ICHA,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAU,QAAS,sCAAuC,EAC1DC,EAAc,QAAS,2CAA4C,EACnEC,EAAS,QAAS,uBAAwB,EA0B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,IAAI,EACJ,GAAK,CAACR,EAAUQ,CAAQ,EACvB,OAAO,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE/G,GAAKP,EAAYO,EAAS,MAAO,EAAI,CAEpC,GADAD,EAAK,KAAOC,EAAQ,KACf,CAACN,EAASK,EAAK,IAAK,EACxBA,EAAK,KAAO,CAAEA,EAAK,IAAK,UACbA,EAAK,KAAK,SAAW,EAChC,OAAO,IAAI,UAAWF,EAAQ,wDAAyD,MAAO,CAAE,EAEjG,IAAM,EAAI,EAAG,EAAIE,EAAK,KAAK,OAAQ,IAClC,GAAK,CAACH,EAAaG,EAAK,KAAM,CAAE,CAAE,EACjC,OAAO,IAAI,UAAWF,EAAQ,iFAAkF,OAAQE,EAAK,KAAM,CAAE,CAAE,CAAE,CAG5I,CACA,OAAKN,EAAYO,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACL,EAASI,EAAK,KAAM,GAClB,IAAI,UAAWF,EAAQ,kFAAmF,QAASE,EAAK,KAAM,CAAE,EAGlI,IACR,CAKAR,EAAO,QAAUO,ICnFjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAW,QAAS,8BAA+B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IAoCf,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAP,EAAQ,UAAW,CAAE,EAChB,CAACT,EAA2BS,CAAM,EACtC,MAAM,IAAI,UAAWL,EAAQ,8GAA+GK,CAAM,CAAE,EASrJ,GAPAK,EAAM,UAAU,OAChBJ,EAAQD,EAAM,OAEdG,EAAO,CAAC,EACRA,EAAK,KAAOP,EAAS,KAAK,MAAM,EAChCO,EAAK,MAAQP,EAAS,MAEjBS,EAAMJ,EAAM,GAIhB,GAHAM,EAAIF,EAAM,EACVN,EAAU,UAAWQ,CAAE,EACvBH,EAAMP,EAAUM,EAAMJ,CAAQ,EACzBK,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GADAC,EAAI,EACCC,EAAED,IAAML,EACZ,MAAM,IAAI,WAAYN,EAAQ,gIAAiIM,EAAOM,EAAED,CAAE,CAAE,EAM7K,IAJAJ,EAAO,IAAI,MAAOD,EAAM,CAAE,EAC1BC,EAAM,CAAE,EAAIF,EACZE,EAAM,CAAE,EAAIT,EAAeO,EAAOG,EAAK,KAAM,EAC7CD,EAAM,CAAE,EAAI,EACJI,EAAIC,EAAGD,IAAM,CACpB,GAAK,CAACd,EAAW,UAAWc,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oFAAqFW,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEvIJ,EAAMI,EAAE,CAAE,EAAI,UAAWA,CAAE,CAC5B,CACA,OAAAJ,EAAMI,EAAE,CAAE,EAAIH,EAAK,KACZT,EAAS,MAAO,KAAMQ,CAAK,CACnC,CAKAZ,EAAO,QAAUQ,ICnFjB,IAAIU,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isArray", "isOrder", "isIndexMode", "format", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeIntegerArray", "isInteger", "shape2strides", "getIndex", "format", "defaults", "validate", "sub2ind", "options", "shape", "ndims", "args", "opts", "err", "len", "i", "j", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 837a6bc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'normalize', the function normalizes - negative subscripts and throws an error when a subscript exceeds array - dimensions. If equal to 'wrap', the function wraps around subscripts - exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 28bf1e4..7482e78 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9a68853 --- /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{primitives as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.1.1-esm/index.mjs";var p={mode:["throw"],order:"row-major"};function l(e,r){var s;if(!i(r))return new TypeError(n("invalid argument. Options argument must be an object. Value: `%s`.",r));if(o(r,"mode")){if(e.mode=r.mode,d(e.mode)){if(0===e.mode.length)return new TypeError(n("invalid option. `%s` option cannot be an empty array.","mode"))}else e.mode=[e.mode];for(s=0;so+1){if(a=l(m,arguments[v=u-1]))throw a}else v=u;if(v-(j=1)!==o)throw new RangeError(n("invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.",o,v-j));for((d=new Array(o+4))[0]=i,d[1]=s(i,m.order),d[2]=0;j ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["validate","opts","options","i","isObject","TypeError","format","hasOwnProp","mode","isArray","length","isIndexMode","order","isOrder","sub2ind","shape","ndims","args","err","len","j","isNonNegativeIntegerArray","arguments","defaults","slice","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;4hCAqDA,SAASA,EAAUC,EAAMC,GACxB,IAAIC,EACJ,IAAMC,EAAUF,GACf,OAAO,IAAIG,UAAWC,EAAQ,qEAAsEJ,IAErG,GAAKK,EAAYL,EAAS,QAAW,CAEpC,GADAD,EAAKO,KAAON,EAAQM,KACdC,EAASR,EAAKO,OAEb,GAA0B,IAArBP,EAAKO,KAAKE,OACrB,OAAO,IAAIL,UAAWC,EAAQ,wDAAyD,cAFvFL,EAAKO,KAAO,CAAEP,EAAKO,MAIpB,IAAML,EAAI,EAAGA,EAAIF,EAAKO,KAAKE,OAAQP,IAClC,IAAMQ,EAAaV,EAAKO,KAAML,IAC7B,OAAO,IAAIE,UAAWC,EAAQ,iFAAkF,OAAQL,EAAKO,KAAML,IAGrI,CACD,OAAKI,EAAYL,EAAS,WACzBD,EAAKW,MAAQV,EAAQU,OACfC,EAASZ,EAAKW,QACZ,IAAIP,UAAWC,EAAQ,kFAAmF,QAASL,EAAKW,QAG1H,IACR,CCdA,SAASE,IACR,IACIC,EACAC,EACAC,EACAhB,EACAiB,EACAC,EACAhB,EACAiB,EAGJ,IAAMC,EADNN,EAAQO,UAAW,IAElB,MAAM,IAAIjB,UAAWC,EAAQ,8GAA+GS,IAS7I,GAPAI,EAAMG,UAAUZ,OAChBM,EAAQD,EAAML,QAEdT,EAAO,CAAA,GACFO,KAAOe,EAASf,KAAKgB,QAC1BvB,EAAKW,MAAQW,EAASX,MAEjBO,EAAMH,EAAM,GAIhB,GADAE,EAAMlB,EAAUC,EADNqB,UADVF,EAAID,EAAM,IAIT,MAAMD,OAGPE,EAAID,EAGL,GAAKC,GADLjB,EAAI,KACSa,EACZ,MAAM,IAAIS,WAAYnB,EAAQ,gIAAiIU,EAAOI,EAAEjB,IAMzK,KAJAc,EAAO,IAAIS,MAAOV,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMU,EAAeZ,EAAOd,EAAKW,OACvCK,EAAM,GAAM,EACJd,EAAIiB,EAAGjB,IAAM,CACpB,IAAMyB,EAAWN,UAAWnB,IAC3B,MAAM,IAAIE,UAAWC,EAAQ,oFAAqFH,EAAGmB,UAAWnB,KAEjIc,EAAMd,EAAE,GAAMmB,UAAWnB,EACzB,CAED,OADAc,EAAMd,EAAE,GAAMF,EAAKO,KACZqB,EAASC,MAAO,KAAMb,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 08e2c51..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 5795b2b..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index cddeb58..add86de 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Convert subscripts to a linear index.", "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,44 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.0", - "@stdlib/assert-is-array": "^0.2.0", - "@stdlib/assert-is-integer": "^0.2.0", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.0", - "@stdlib/assert-is-plain-object": "^0.2.0", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.2.0", - "@stdlib/ndarray-base-assert-is-order": "^0.2.0", - "@stdlib/ndarray-base-shape2strides": "^0.2.0", - "@stdlib/ndarray-base-sub2ind": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1" - }, - "devDependencies": { - "@stdlib/math-base-special-floor": "^0.2.0", - "@stdlib/ndarray-base-numel": "^0.2.0", - "@stdlib/random-base-discrete-uniform": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -93,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..73bdcb6 --- /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 c44bc30..0000000 --- a/test/test.js +++ /dev/null @@ -1,588 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'normalizes', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'normalize', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, -999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, -1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -2, -2, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, -1, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index a501cdf..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw', 'normalize' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 026c46df021bf8c2c87037fef4c469d7fb10ea46 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:33:51 +0000 Subject: [PATCH 082/108] 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 01b52a6..015dd00 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import sub2ind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-sub2ind@esm/index.mjs'; +import sub2ind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-sub2ind@v0.2.0-esm/index.mjs'; ``` #### sub2ind( shape, ...subscripts\[, options] ) @@ -147,7 +147,7 @@ var idx = sub2ind( shape, -2, 10, -1, opts ); - - - - From 55343549eab212062d7ef1d2d624ee15ee681655 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:11:03 +0000 Subject: [PATCH 086/108] 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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 552 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 67 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 588 --- test/test.validate.js | 186 - 48 files changed, 4867 insertions(+), 5371 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 5cd5c02..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 0e89cdf..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: '19 19 * * 2' - - # 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 + + ```
@@ -240,7 +231,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -305,11 +296,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/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 7268bb4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,552 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=normalize', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'normalize' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[normalize]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'normalize' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5065893..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-sub2ind/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 f14e96a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sub2ind from '../docs/types/index'; -export = sub2ind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a32fda4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var m=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var g=m(function(k,h){h.exports={mode:["throw"],order:"row-major"}});var p=m(function(F,f){ -var q=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),y=require('@stdlib/assert-is-array/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),O=require('@stdlib/ndarray-base-assert-is-index-mode/dist'),d=require('@stdlib/error-tools-fmtprodmsg/dist');function T(e,r){var i;if(!q(r))return new TypeError(d('0kF2V',r));if(l(r,"mode")){if(e.mode=r.mode,!y(e.mode))e.mode=[e.mode];else if(e.mode.length===0)return new TypeError(d('0kF5r',"mode"));for(i=0;ii+1){if(o=u-1,e=arguments[o],s=N(t,e),s)throw s}else o=u;if(n=1,o-n!==i)throw new RangeError(v('0kF5p',i,o-n));for(a=new Array(i+4),a[0]=r,a[1]=A(r,t.order),a[2]=0;n ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,CAAE,OAAQ,EAClB,MAAS,WACV,ICHA,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAU,QAAS,sCAAuC,EAC1DC,EAAc,QAAS,2CAA4C,EACnEC,EAAS,QAAS,uBAAwB,EA0B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,IAAI,EACJ,GAAK,CAACR,EAAUQ,CAAQ,EACvB,OAAO,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE/G,GAAKP,EAAYO,EAAS,MAAO,EAAI,CAEpC,GADAD,EAAK,KAAOC,EAAQ,KACf,CAACN,EAASK,EAAK,IAAK,EACxBA,EAAK,KAAO,CAAEA,EAAK,IAAK,UACbA,EAAK,KAAK,SAAW,EAChC,OAAO,IAAI,UAAWF,EAAQ,wDAAyD,MAAO,CAAE,EAEjG,IAAM,EAAI,EAAG,EAAIE,EAAK,KAAK,OAAQ,IAClC,GAAK,CAACH,EAAaG,EAAK,KAAM,CAAE,CAAE,EACjC,OAAO,IAAI,UAAWF,EAAQ,iFAAkF,OAAQE,EAAK,KAAM,CAAE,CAAE,CAAE,CAG5I,CACA,OAAKN,EAAYO,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACL,EAASI,EAAK,KAAM,GAClB,IAAI,UAAWF,EAAQ,kFAAmF,QAASE,EAAK,KAAM,CAAE,EAGlI,IACR,CAKAR,EAAO,QAAUO,ICnFjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAW,QAAS,8BAA+B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IAoCf,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAP,EAAQ,UAAW,CAAE,EAChB,CAACT,EAA2BS,CAAM,EACtC,MAAM,IAAI,UAAWL,EAAQ,8GAA+GK,CAAM,CAAE,EASrJ,GAPAK,EAAM,UAAU,OAChBJ,EAAQD,EAAM,OAEdG,EAAO,CAAC,EACRA,EAAK,KAAOP,EAAS,KAAK,MAAM,EAChCO,EAAK,MAAQP,EAAS,MAEjBS,EAAMJ,EAAM,GAIhB,GAHAM,EAAIF,EAAM,EACVN,EAAU,UAAWQ,CAAE,EACvBH,EAAMP,EAAUM,EAAMJ,CAAQ,EACzBK,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GADAC,EAAI,EACCC,EAAED,IAAML,EACZ,MAAM,IAAI,WAAYN,EAAQ,gIAAiIM,EAAOM,EAAED,CAAE,CAAE,EAM7K,IAJAJ,EAAO,IAAI,MAAOD,EAAM,CAAE,EAC1BC,EAAM,CAAE,EAAIF,EACZE,EAAM,CAAE,EAAIT,EAAeO,EAAOG,EAAK,KAAM,EAC7CD,EAAM,CAAE,EAAI,EACJI,EAAIC,EAAGD,IAAM,CACpB,GAAK,CAACd,EAAW,UAAWc,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oFAAqFW,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEvIJ,EAAMI,EAAE,CAAE,EAAI,UAAWA,CAAE,CAC5B,CACA,OAAAJ,EAAMI,EAAE,CAAE,EAAIH,EAAK,KACZT,EAAS,MAAO,KAAMQ,CAAK,CACnC,CAKAZ,EAAO,QAAUQ,ICnFjB,IAAIU,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isArray", "isOrder", "isIndexMode", "format", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeIntegerArray", "isInteger", "shape2strides", "getIndex", "format", "defaults", "validate", "sub2ind", "options", "shape", "ndims", "args", "opts", "err", "len", "i", "j", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 837a6bc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'normalize', the function normalizes - negative subscripts and throws an error when a subscript exceeds array - dimensions. If equal to 'wrap', the function wraps around subscripts - exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 28bf1e4..7482e78 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7b7d78a --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.1-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.2.0-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(){var p,j,h,f,v,g,b,w;if(!r(p=arguments[0]))throw new TypeError(d("0kF5o",p));if(g=arguments.length,j=p.length,(f={}).mode=l.mode.slice(),f.order=l.order,g>j+1){if(v=function(r,e){var s;if(!o(e))return new TypeError(d("0kF2V",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r","mode"))}else r.mode=[r.mode];for(s=0;s ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isArray from '@stdlib/assert-is-array';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isIndexMode from '@stdlib/ndarray-base-assert-is-index-mode';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions\n* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'mode': 'throw',\n* 'order': 'column-major'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tvar i;\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0kF2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t\tif ( !isArray( opts.mode ) ) {\n\t\t\topts.mode = [ opts.mode ];\n\t\t} else if ( opts.mode.length === 0 ) {\n\t\t\treturn new TypeError( format( '0kF5r', 'mode' ) );\n\t\t}\n\t\tfor ( i = 0; i < opts.mode.length; i++ ) {\n\t\t\tif ( !isIndexMode( opts.mode[ i ] ) ) {\n\t\t\t\treturn new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) );\n\t\t\t}\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t\tif ( !isOrder( opts.order ) ) {\n\t\t\treturn new TypeError( format( '0kF5n', 'order', opts.order ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["sub2ind","shape","ndims","args","opts","err","len","i","j","isNonNegativeIntegerArray","arguments","TypeError","format","length","mode","defaults","slice","order","options","isObject","hasOwnProp","isArray","isIndexMode","isOrder","validate","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAgEA,SAASA,IACR,IACIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,IAAMC,EADNR,EAAQS,UAAW,IAElB,MAAM,IAAIC,UAAWC,EAAQ,QAASX,IASvC,GAPAK,EAAMI,UAAUG,OAChBX,EAAQD,EAAMY,QAEdT,EAAO,CAAA,GACFU,KAAOC,EAASD,KAAKE,QAC1BZ,EAAKa,MAAQF,EAASE,MAEjBX,EAAMJ,EAAM,GAIhB,GADAG,ECpCF,SAAmBD,EAAMc,GACxB,IAAIX,EACJ,IAAMY,EAAUD,GACf,OAAO,IAAIP,UAAWC,EAAQ,QAASM,IAExC,GAAKE,EAAYF,EAAS,QAAW,CAEpC,GADAd,EAAKU,KAAOI,EAAQJ,KACdO,EAASjB,EAAKU,OAEb,GAA0B,IAArBV,EAAKU,KAAKD,OACrB,OAAO,IAAIF,UAAWC,EAAQ,QAAS,cAFvCR,EAAKU,KAAO,CAAEV,EAAKU,MAIpB,IAAMP,EAAI,EAAGA,EAAIH,EAAKU,KAAKD,OAAQN,IAClC,IAAMe,EAAalB,EAAKU,KAAMP,IAC7B,OAAO,IAAII,UAAWC,EAAQ,QAAS,OAAQR,EAAKU,KAAMP,IAG5D,CACD,OAAKa,EAAYF,EAAS,WACzBd,EAAKa,MAAQC,EAAQD,OACfM,EAASnB,EAAKa,QACZ,IAAIN,UAAWC,EAAQ,QAAS,QAASR,EAAKa,QAGhD,IACR,CDWQO,CAAUpB,EADNM,UADVF,EAAIF,EAAM,IAGLD,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GAAKE,GADLD,EAAI,KACSL,EACZ,MAAM,IAAIuB,WAAYb,EAAQ,QAASV,EAAOM,EAAED,IAMjD,KAJAJ,EAAO,IAAIuB,MAAOxB,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMwB,EAAe1B,EAAOG,EAAKa,OACvCd,EAAM,GAAM,EACJI,EAAIC,EAAGD,IAAM,CACpB,IAAMqB,EAAWlB,UAAWH,IAC3B,MAAM,IAAII,UAAWC,EAAQ,QAASL,EAAGG,UAAWH,KAErDJ,EAAMI,EAAE,GAAMG,UAAWH,EACzB,CAED,OADAJ,EAAMI,EAAE,GAAMH,EAAKU,KACZe,EAASC,MAAO,KAAM3B,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4c9df15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0kF5o', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( '0kF5p', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( '0kF5q', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 241a6b1..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0kF2V', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0kF5r', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0kF5n', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index eebe2b7..0d98129 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Convert subscripts to a linear index.", "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/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.2.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.1", - "@stdlib/ndarray-base-shape2strides": "^0.2.1", - "@stdlib/ndarray-base-sub2ind": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/math-base-special-floor": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^0.2.0", - "@stdlib/random-base-randu": "^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", @@ -94,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..240fcea --- /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 c44bc30..0000000 --- a/test/test.js +++ /dev/null @@ -1,588 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'normalizes', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'normalize', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, -999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, -1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -2, -2, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, -1, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index a501cdf..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw', 'normalize' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 5cfa3bc4a0d230cd99db30de26ba3cc43e80f070 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:51:11 +0000 Subject: [PATCH 087/108] 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 a499e22..4f9a486 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import sub2ind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-sub2ind@esm/index.mjs'; +import sub2ind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-sub2ind@v0.2.1-esm/index.mjs'; ``` #### sub2ind( shape, ...subscripts\[, options] ) @@ -147,7 +147,7 @@ var idx = sub2ind( shape, -2, 10, -1, opts ); - - - - From c823219353d5bf51b017c7bc8827e08e1391cab9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 14:06:09 +0000 Subject: [PATCH 091/108] 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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 552 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 67 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 588 --- test/test.validate.js | 186 - 49 files changed, 4867 insertions(+), 5373 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 aac9bb8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T06:01:04.603Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 5cd5c02..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 0e89cdf..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: '19 19 * * 2' - - # 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 + + ```
@@ -240,7 +231,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -305,11 +296,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/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 7268bb4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,552 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=normalize', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'normalize' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[normalize]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'normalize' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5065893..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-sub2ind/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 f14e96a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sub2ind from '../docs/types/index'; -export = sub2ind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a32fda4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var m=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var g=m(function(k,h){h.exports={mode:["throw"],order:"row-major"}});var p=m(function(F,f){ -var q=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),y=require('@stdlib/assert-is-array/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),O=require('@stdlib/ndarray-base-assert-is-index-mode/dist'),d=require('@stdlib/error-tools-fmtprodmsg/dist');function T(e,r){var i;if(!q(r))return new TypeError(d('0kF2V',r));if(l(r,"mode")){if(e.mode=r.mode,!y(e.mode))e.mode=[e.mode];else if(e.mode.length===0)return new TypeError(d('0kF5r',"mode"));for(i=0;ii+1){if(o=u-1,e=arguments[o],s=N(t,e),s)throw s}else o=u;if(n=1,o-n!==i)throw new RangeError(v('0kF5p',i,o-n));for(a=new Array(i+4),a[0]=r,a[1]=A(r,t.order),a[2]=0;n ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,CAAE,OAAQ,EAClB,MAAS,WACV,ICHA,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAU,QAAS,sCAAuC,EAC1DC,EAAc,QAAS,2CAA4C,EACnEC,EAAS,QAAS,uBAAwB,EA0B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,IAAI,EACJ,GAAK,CAACR,EAAUQ,CAAQ,EACvB,OAAO,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE/G,GAAKP,EAAYO,EAAS,MAAO,EAAI,CAEpC,GADAD,EAAK,KAAOC,EAAQ,KACf,CAACN,EAASK,EAAK,IAAK,EACxBA,EAAK,KAAO,CAAEA,EAAK,IAAK,UACbA,EAAK,KAAK,SAAW,EAChC,OAAO,IAAI,UAAWF,EAAQ,wDAAyD,MAAO,CAAE,EAEjG,IAAM,EAAI,EAAG,EAAIE,EAAK,KAAK,OAAQ,IAClC,GAAK,CAACH,EAAaG,EAAK,KAAM,CAAE,CAAE,EACjC,OAAO,IAAI,UAAWF,EAAQ,iFAAkF,OAAQE,EAAK,KAAM,CAAE,CAAE,CAAE,CAG5I,CACA,OAAKN,EAAYO,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACL,EAASI,EAAK,KAAM,GAClB,IAAI,UAAWF,EAAQ,kFAAmF,QAASE,EAAK,KAAM,CAAE,EAGlI,IACR,CAKAR,EAAO,QAAUO,ICnFjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAW,QAAS,8BAA+B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IAoCf,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAP,EAAQ,UAAW,CAAE,EAChB,CAACT,EAA2BS,CAAM,EACtC,MAAM,IAAI,UAAWL,EAAQ,8GAA+GK,CAAM,CAAE,EASrJ,GAPAK,EAAM,UAAU,OAChBJ,EAAQD,EAAM,OAEdG,EAAO,CAAC,EACRA,EAAK,KAAOP,EAAS,KAAK,MAAM,EAChCO,EAAK,MAAQP,EAAS,MAEjBS,EAAMJ,EAAM,GAIhB,GAHAM,EAAIF,EAAM,EACVN,EAAU,UAAWQ,CAAE,EACvBH,EAAMP,EAAUM,EAAMJ,CAAQ,EACzBK,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GADAC,EAAI,EACCC,EAAED,IAAML,EACZ,MAAM,IAAI,WAAYN,EAAQ,gIAAiIM,EAAOM,EAAED,CAAE,CAAE,EAM7K,IAJAJ,EAAO,IAAI,MAAOD,EAAM,CAAE,EAC1BC,EAAM,CAAE,EAAIF,EACZE,EAAM,CAAE,EAAIT,EAAeO,EAAOG,EAAK,KAAM,EAC7CD,EAAM,CAAE,EAAI,EACJI,EAAIC,EAAGD,IAAM,CACpB,GAAK,CAACd,EAAW,UAAWc,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oFAAqFW,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEvIJ,EAAMI,EAAE,CAAE,EAAI,UAAWA,CAAE,CAC5B,CACA,OAAAJ,EAAMI,EAAE,CAAE,EAAIH,EAAK,KACZT,EAAS,MAAO,KAAMQ,CAAK,CACnC,CAKAZ,EAAO,QAAUQ,ICnFjB,IAAIU,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isArray", "isOrder", "isIndexMode", "format", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeIntegerArray", "isInteger", "shape2strides", "getIndex", "format", "defaults", "validate", "sub2ind", "options", "shape", "ndims", "args", "opts", "err", "len", "i", "j", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 837a6bc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'normalize', the function normalizes - negative subscripts and throws an error when a subscript exceeds array - dimensions. If equal to 'wrap', the function wraps around subscripts - exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 28bf1e4..7482e78 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..374245b --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.1-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.2.1-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(){var p,j,h,f,v,g,b,w;if(!r(p=arguments[0]))throw new TypeError(d("0kF5o",p));if(g=arguments.length,j=p.length,(f={}).mode=l.mode.slice(),f.order=l.order,g>j+1){if(v=function(r,e){var s;if(!o(e))return new TypeError(d("0kF2V",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r","mode"))}else r.mode=[r.mode];for(s=0;s ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isArray from '@stdlib/assert-is-array';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isIndexMode from '@stdlib/ndarray-base-assert-is-index-mode';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions\n* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'mode': 'throw',\n* 'order': 'column-major'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tvar i;\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0kF2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t\tif ( !isArray( opts.mode ) ) {\n\t\t\topts.mode = [ opts.mode ];\n\t\t} else if ( opts.mode.length === 0 ) {\n\t\t\treturn new TypeError( format( '0kF5r', 'mode' ) );\n\t\t}\n\t\tfor ( i = 0; i < opts.mode.length; i++ ) {\n\t\t\tif ( !isIndexMode( opts.mode[ i ] ) ) {\n\t\t\t\treturn new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) );\n\t\t\t}\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t\tif ( !isOrder( opts.order ) ) {\n\t\t\treturn new TypeError( format( '0kF5n', 'order', opts.order ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["sub2ind","shape","ndims","args","opts","err","len","i","j","isNonNegativeIntegerArray","arguments","TypeError","format","length","mode","defaults","slice","order","options","isObject","hasOwnProp","isArray","isIndexMode","isOrder","validate","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAgEA,SAASA,IACR,IACIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,IAAMC,EADNR,EAAQS,UAAW,IAElB,MAAM,IAAIC,UAAWC,EAAQ,QAASX,IASvC,GAPAK,EAAMI,UAAUG,OAChBX,EAAQD,EAAMY,QAEdT,EAAO,CAAA,GACFU,KAAOC,EAASD,KAAKE,QAC1BZ,EAAKa,MAAQF,EAASE,MAEjBX,EAAMJ,EAAM,GAIhB,GADAG,ECpCF,SAAmBD,EAAMc,GACxB,IAAIX,EACJ,IAAMY,EAAUD,GACf,OAAO,IAAIP,UAAWC,EAAQ,QAASM,IAExC,GAAKE,EAAYF,EAAS,QAAW,CAEpC,GADAd,EAAKU,KAAOI,EAAQJ,KACdO,EAASjB,EAAKU,OAEb,GAA0B,IAArBV,EAAKU,KAAKD,OACrB,OAAO,IAAIF,UAAWC,EAAQ,QAAS,cAFvCR,EAAKU,KAAO,CAAEV,EAAKU,MAIpB,IAAMP,EAAI,EAAGA,EAAIH,EAAKU,KAAKD,OAAQN,IAClC,IAAMe,EAAalB,EAAKU,KAAMP,IAC7B,OAAO,IAAII,UAAWC,EAAQ,QAAS,OAAQR,EAAKU,KAAMP,IAG5D,CACD,OAAKa,EAAYF,EAAS,WACzBd,EAAKa,MAAQC,EAAQD,OACfM,EAASnB,EAAKa,QACZ,IAAIN,UAAWC,EAAQ,QAAS,QAASR,EAAKa,QAGhD,IACR,CDWQO,CAAUpB,EADNM,UADVF,EAAIF,EAAM,IAGLD,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GAAKE,GADLD,EAAI,KACSL,EACZ,MAAM,IAAIuB,WAAYb,EAAQ,QAASV,EAAOM,EAAED,IAMjD,KAJAJ,EAAO,IAAIuB,MAAOxB,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMwB,EAAe1B,EAAOG,EAAKa,OACvCd,EAAM,GAAM,EACJI,EAAIC,EAAGD,IAAM,CACpB,IAAMqB,EAAWlB,UAAWH,IAC3B,MAAM,IAAII,UAAWC,EAAQ,QAASL,EAAGG,UAAWH,KAErDJ,EAAMI,EAAE,GAAMG,UAAWH,EACzB,CAED,OADAJ,EAAMI,EAAE,GAAMH,EAAKU,KACZe,EAASC,MAAO,KAAM3B,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4c9df15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0kF5o', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( '0kF5p', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( '0kF5q', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 241a6b1..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0kF2V', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0kF5r', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0kF5n', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 4ae73fd..0d98129 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Convert subscripts to a linear index.", "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/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.2.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.1", - "@stdlib/ndarray-base-shape2strides": "^0.2.1", - "@stdlib/ndarray-base-sub2ind": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/math-base-special-floor": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^0.2.1", - "@stdlib/random-base-randu": "^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", @@ -94,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..dfe5804 --- /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 c44bc30..0000000 --- a/test/test.js +++ /dev/null @@ -1,588 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'normalizes', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'normalize', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, -999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, -1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -2, -2, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, -1, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index a501cdf..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw', 'normalize' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 7300a717dedf4681a86b03c13dfa0ce85705a0f9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:36:42 +0000 Subject: [PATCH 092/108] Transform error messages --- lib/main.js | 8 ++++---- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/main.js b/lib/main.js index 08e2c51..4c9df15 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0kF5o', shape ) ); } len = arguments.length; ndims = shape.length; @@ -96,7 +96,7 @@ function sub2ind() { } i = 1; if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); + throw new RangeError( format( '0kF5p', ndims, j-i ) ); } args = new Array( ndims+4 ); args[ 0 ] = shape; @@ -104,7 +104,7 @@ function sub2ind() { args[ 2 ] = 0; // strides are positive, so offset is always zero for ( ; i < j; i++ ) { if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); + throw new TypeError( format( '0kF5q', i, arguments[ i ] ) ); } args[ i+2 ] = arguments[ i ]; } diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..241a6b1 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0kF2V', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0kF5r', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0kF5n', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 346ef8a..824f9c1 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.2.1", "@stdlib/ndarray-base-shape2strides": "^0.2.1", "@stdlib/ndarray-base-sub2ind": "^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 22624e07ba9110aeef7b7a99cc7a836a8476d8c9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 13:08:05 +0000 Subject: [PATCH 093/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4921 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 7482e78..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 374245b..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.1-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.2.1-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(){var p,j,h,f,v,g,b,w;if(!r(p=arguments[0]))throw new TypeError(d("0kF5o",p));if(g=arguments.length,j=p.length,(f={}).mode=l.mode.slice(),f.order=l.order,g>j+1){if(v=function(r,e){var s;if(!o(e))return new TypeError(d("0kF2V",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r","mode"))}else r.mode=[r.mode];for(s=0;s ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isArray from '@stdlib/assert-is-array';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isIndexMode from '@stdlib/ndarray-base-assert-is-index-mode';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions\n* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'mode': 'throw',\n* 'order': 'column-major'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tvar i;\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0kF2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t\tif ( !isArray( opts.mode ) ) {\n\t\t\topts.mode = [ opts.mode ];\n\t\t} else if ( opts.mode.length === 0 ) {\n\t\t\treturn new TypeError( format( '0kF5r', 'mode' ) );\n\t\t}\n\t\tfor ( i = 0; i < opts.mode.length; i++ ) {\n\t\t\tif ( !isIndexMode( opts.mode[ i ] ) ) {\n\t\t\t\treturn new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) );\n\t\t\t}\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t\tif ( !isOrder( opts.order ) ) {\n\t\t\treturn new TypeError( format( '0kF5n', 'order', opts.order ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["sub2ind","shape","ndims","args","opts","err","len","i","j","isNonNegativeIntegerArray","arguments","TypeError","format","length","mode","defaults","slice","order","options","isObject","hasOwnProp","isArray","isIndexMode","isOrder","validate","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAgEA,SAASA,IACR,IACIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,IAAMC,EADNR,EAAQS,UAAW,IAElB,MAAM,IAAIC,UAAWC,EAAQ,QAASX,IASvC,GAPAK,EAAMI,UAAUG,OAChBX,EAAQD,EAAMY,QAEdT,EAAO,CAAA,GACFU,KAAOC,EAASD,KAAKE,QAC1BZ,EAAKa,MAAQF,EAASE,MAEjBX,EAAMJ,EAAM,GAIhB,GADAG,ECpCF,SAAmBD,EAAMc,GACxB,IAAIX,EACJ,IAAMY,EAAUD,GACf,OAAO,IAAIP,UAAWC,EAAQ,QAASM,IAExC,GAAKE,EAAYF,EAAS,QAAW,CAEpC,GADAd,EAAKU,KAAOI,EAAQJ,KACdO,EAASjB,EAAKU,OAEb,GAA0B,IAArBV,EAAKU,KAAKD,OACrB,OAAO,IAAIF,UAAWC,EAAQ,QAAS,cAFvCR,EAAKU,KAAO,CAAEV,EAAKU,MAIpB,IAAMP,EAAI,EAAGA,EAAIH,EAAKU,KAAKD,OAAQN,IAClC,IAAMe,EAAalB,EAAKU,KAAMP,IAC7B,OAAO,IAAII,UAAWC,EAAQ,QAAS,OAAQR,EAAKU,KAAMP,IAG5D,CACD,OAAKa,EAAYF,EAAS,WACzBd,EAAKa,MAAQC,EAAQD,OACfM,EAASnB,EAAKa,QACZ,IAAIN,UAAWC,EAAQ,QAAS,QAASR,EAAKa,QAGhD,IACR,CDWQO,CAAUpB,EADNM,UADVF,EAAIF,EAAM,IAGLD,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GAAKE,GADLD,EAAI,KACSL,EACZ,MAAM,IAAIuB,WAAYb,EAAQ,QAASV,EAAOM,EAAED,IAMjD,KAJAJ,EAAO,IAAIuB,MAAOxB,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMwB,EAAe1B,EAAOG,EAAKa,OACvCd,EAAM,GAAM,EACJI,EAAIC,EAAGD,IAAM,CACpB,IAAMqB,EAAWlB,UAAWH,IAC3B,MAAM,IAAII,UAAWC,EAAQ,QAASL,EAAGG,UAAWH,KAErDJ,EAAMI,EAAE,GAAMG,UAAWH,EACzB,CAED,OADAJ,EAAMI,EAAE,GAAMH,EAAKU,KACZe,EAASC,MAAO,KAAM3B,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index dfe5804..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 057c9e43f1f52500e5704edbab0522a43f255a97 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 13:08:19 +0000 Subject: [PATCH 094/108] 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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 552 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 67 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 588 --- test/test.validate.js | 186 - 49 files changed, 4867 insertions(+), 5376 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 8d421f1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T05:17:03.670Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 5cd5c02..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 0e89cdf..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: '19 19 * * 2' - - # 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 + + ```
@@ -240,7 +231,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -305,11 +296,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/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 7268bb4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,552 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=normalize', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'normalize' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[normalize]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'normalize' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5065893..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-sub2ind/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 f14e96a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sub2ind from '../docs/types/index'; -export = sub2ind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a32fda4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var m=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var g=m(function(k,h){h.exports={mode:["throw"],order:"row-major"}});var p=m(function(F,f){ -var q=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),y=require('@stdlib/assert-is-array/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),O=require('@stdlib/ndarray-base-assert-is-index-mode/dist'),d=require('@stdlib/error-tools-fmtprodmsg/dist');function T(e,r){var i;if(!q(r))return new TypeError(d('0kF2V',r));if(l(r,"mode")){if(e.mode=r.mode,!y(e.mode))e.mode=[e.mode];else if(e.mode.length===0)return new TypeError(d('0kF5r',"mode"));for(i=0;ii+1){if(o=u-1,e=arguments[o],s=N(t,e),s)throw s}else o=u;if(n=1,o-n!==i)throw new RangeError(v('0kF5p',i,o-n));for(a=new Array(i+4),a[0]=r,a[1]=A(r,t.order),a[2]=0;n ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,CAAE,OAAQ,EAClB,MAAS,WACV,ICHA,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAU,QAAS,sCAAuC,EAC1DC,EAAc,QAAS,2CAA4C,EACnEC,EAAS,QAAS,uBAAwB,EA0B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,IAAI,EACJ,GAAK,CAACR,EAAUQ,CAAQ,EACvB,OAAO,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE/G,GAAKP,EAAYO,EAAS,MAAO,EAAI,CAEpC,GADAD,EAAK,KAAOC,EAAQ,KACf,CAACN,EAASK,EAAK,IAAK,EACxBA,EAAK,KAAO,CAAEA,EAAK,IAAK,UACbA,EAAK,KAAK,SAAW,EAChC,OAAO,IAAI,UAAWF,EAAQ,wDAAyD,MAAO,CAAE,EAEjG,IAAM,EAAI,EAAG,EAAIE,EAAK,KAAK,OAAQ,IAClC,GAAK,CAACH,EAAaG,EAAK,KAAM,CAAE,CAAE,EACjC,OAAO,IAAI,UAAWF,EAAQ,iFAAkF,OAAQE,EAAK,KAAM,CAAE,CAAE,CAAE,CAG5I,CACA,OAAKN,EAAYO,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACL,EAASI,EAAK,KAAM,GAClB,IAAI,UAAWF,EAAQ,kFAAmF,QAASE,EAAK,KAAM,CAAE,EAGlI,IACR,CAKAR,EAAO,QAAUO,ICnFjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAW,QAAS,8BAA+B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IAoCf,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAP,EAAQ,UAAW,CAAE,EAChB,CAACT,EAA2BS,CAAM,EACtC,MAAM,IAAI,UAAWL,EAAQ,8GAA+GK,CAAM,CAAE,EASrJ,GAPAK,EAAM,UAAU,OAChBJ,EAAQD,EAAM,OAEdG,EAAO,CAAC,EACRA,EAAK,KAAOP,EAAS,KAAK,MAAM,EAChCO,EAAK,MAAQP,EAAS,MAEjBS,EAAMJ,EAAM,GAIhB,GAHAM,EAAIF,EAAM,EACVN,EAAU,UAAWQ,CAAE,EACvBH,EAAMP,EAAUM,EAAMJ,CAAQ,EACzBK,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GADAC,EAAI,EACCC,EAAED,IAAML,EACZ,MAAM,IAAI,WAAYN,EAAQ,gIAAiIM,EAAOM,EAAED,CAAE,CAAE,EAM7K,IAJAJ,EAAO,IAAI,MAAOD,EAAM,CAAE,EAC1BC,EAAM,CAAE,EAAIF,EACZE,EAAM,CAAE,EAAIT,EAAeO,EAAOG,EAAK,KAAM,EAC7CD,EAAM,CAAE,EAAI,EACJI,EAAIC,EAAGD,IAAM,CACpB,GAAK,CAACd,EAAW,UAAWc,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oFAAqFW,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEvIJ,EAAMI,EAAE,CAAE,EAAI,UAAWA,CAAE,CAC5B,CACA,OAAAJ,EAAMI,EAAE,CAAE,EAAIH,EAAK,KACZT,EAAS,MAAO,KAAMQ,CAAK,CACnC,CAKAZ,EAAO,QAAUQ,ICnFjB,IAAIU,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isArray", "isOrder", "isIndexMode", "format", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeIntegerArray", "isInteger", "shape2strides", "getIndex", "format", "defaults", "validate", "sub2ind", "options", "shape", "ndims", "args", "opts", "err", "len", "i", "j", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 837a6bc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'normalize', the function normalizes - negative subscripts and throws an error when a subscript exceeds array - dimensions. If equal to 'wrap', the function wraps around subscripts - exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 28bf1e4..7482e78 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..374245b --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.1-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.2.1-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(){var p,j,h,f,v,g,b,w;if(!r(p=arguments[0]))throw new TypeError(d("0kF5o",p));if(g=arguments.length,j=p.length,(f={}).mode=l.mode.slice(),f.order=l.order,g>j+1){if(v=function(r,e){var s;if(!o(e))return new TypeError(d("0kF2V",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r","mode"))}else r.mode=[r.mode];for(s=0;s ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isArray from '@stdlib/assert-is-array';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isIndexMode from '@stdlib/ndarray-base-assert-is-index-mode';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions\n* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'mode': 'throw',\n* 'order': 'column-major'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tvar i;\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0kF2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t\tif ( !isArray( opts.mode ) ) {\n\t\t\topts.mode = [ opts.mode ];\n\t\t} else if ( opts.mode.length === 0 ) {\n\t\t\treturn new TypeError( format( '0kF5r', 'mode' ) );\n\t\t}\n\t\tfor ( i = 0; i < opts.mode.length; i++ ) {\n\t\t\tif ( !isIndexMode( opts.mode[ i ] ) ) {\n\t\t\t\treturn new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) );\n\t\t\t}\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t\tif ( !isOrder( opts.order ) ) {\n\t\t\treturn new TypeError( format( '0kF5n', 'order', opts.order ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["sub2ind","shape","ndims","args","opts","err","len","i","j","isNonNegativeIntegerArray","arguments","TypeError","format","length","mode","defaults","slice","order","options","isObject","hasOwnProp","isArray","isIndexMode","isOrder","validate","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAgEA,SAASA,IACR,IACIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,IAAMC,EADNR,EAAQS,UAAW,IAElB,MAAM,IAAIC,UAAWC,EAAQ,QAASX,IASvC,GAPAK,EAAMI,UAAUG,OAChBX,EAAQD,EAAMY,QAEdT,EAAO,CAAA,GACFU,KAAOC,EAASD,KAAKE,QAC1BZ,EAAKa,MAAQF,EAASE,MAEjBX,EAAMJ,EAAM,GAIhB,GADAG,ECpCF,SAAmBD,EAAMc,GACxB,IAAIX,EACJ,IAAMY,EAAUD,GACf,OAAO,IAAIP,UAAWC,EAAQ,QAASM,IAExC,GAAKE,EAAYF,EAAS,QAAW,CAEpC,GADAd,EAAKU,KAAOI,EAAQJ,KACdO,EAASjB,EAAKU,OAEb,GAA0B,IAArBV,EAAKU,KAAKD,OACrB,OAAO,IAAIF,UAAWC,EAAQ,QAAS,cAFvCR,EAAKU,KAAO,CAAEV,EAAKU,MAIpB,IAAMP,EAAI,EAAGA,EAAIH,EAAKU,KAAKD,OAAQN,IAClC,IAAMe,EAAalB,EAAKU,KAAMP,IAC7B,OAAO,IAAII,UAAWC,EAAQ,QAAS,OAAQR,EAAKU,KAAMP,IAG5D,CACD,OAAKa,EAAYF,EAAS,WACzBd,EAAKa,MAAQC,EAAQD,OACfM,EAASnB,EAAKa,QACZ,IAAIN,UAAWC,EAAQ,QAAS,QAASR,EAAKa,QAGhD,IACR,CDWQO,CAAUpB,EADNM,UADVF,EAAIF,EAAM,IAGLD,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GAAKE,GADLD,EAAI,KACSL,EACZ,MAAM,IAAIuB,WAAYb,EAAQ,QAASV,EAAOM,EAAED,IAMjD,KAJAJ,EAAO,IAAIuB,MAAOxB,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMwB,EAAe1B,EAAOG,EAAKa,OACvCd,EAAM,GAAM,EACJI,EAAIC,EAAGD,IAAM,CACpB,IAAMqB,EAAWlB,UAAWH,IAC3B,MAAM,IAAII,UAAWC,EAAQ,QAASL,EAAGG,UAAWH,KAErDJ,EAAMI,EAAE,GAAMG,UAAWH,EACzB,CAED,OADAJ,EAAMI,EAAE,GAAMH,EAAKU,KACZe,EAASC,MAAO,KAAM3B,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4c9df15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0kF5o', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( '0kF5p', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( '0kF5q', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 241a6b1..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0kF2V', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0kF5r', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0kF5n', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 824f9c1..0d98129 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Convert subscripts to a linear index.", "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/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.2.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.1", - "@stdlib/ndarray-base-shape2strides": "^0.2.1", - "@stdlib/ndarray-base-sub2ind": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/math-base-special-floor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^0.2.1", - "@stdlib/random-base-randu": "^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", @@ -94,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..dfe5804 --- /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 c44bc30..0000000 --- a/test/test.js +++ /dev/null @@ -1,588 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'normalizes', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'normalize', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, -999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, -1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -2, -2, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, -1, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index a501cdf..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw', 'normalize' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From afd609d17c708414b3624d42b0ddc68b553d9284 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:51:15 +0000 Subject: [PATCH 095/108] Transform error messages --- lib/main.js | 8 ++++---- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/main.js b/lib/main.js index 08e2c51..4c9df15 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0kF5o', shape ) ); } len = arguments.length; ndims = shape.length; @@ -96,7 +96,7 @@ function sub2ind() { } i = 1; if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); + throw new RangeError( format( '0kF5p', ndims, j-i ) ); } args = new Array( ndims+4 ); args[ 0 ] = shape; @@ -104,7 +104,7 @@ function sub2ind() { args[ 2 ] = 0; // strides are positive, so offset is always zero for ( ; i < j; i++ ) { if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); + throw new TypeError( format( '0kF5q', i, arguments[ i ] ) ); } args[ i+2 ] = arguments[ i ]; } diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..241a6b1 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0kF2V', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0kF5r', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0kF5n', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 346ef8a..824f9c1 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.2.1", "@stdlib/ndarray-base-shape2strides": "^0.2.1", "@stdlib/ndarray-base-sub2ind": "^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 60aeb2d232e9c58ebfae332bccf223a92d9bdb83 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:17:22 +0000 Subject: [PATCH 096/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4921 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 7482e78..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 374245b..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.1-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.2.1-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(){var p,j,h,f,v,g,b,w;if(!r(p=arguments[0]))throw new TypeError(d("0kF5o",p));if(g=arguments.length,j=p.length,(f={}).mode=l.mode.slice(),f.order=l.order,g>j+1){if(v=function(r,e){var s;if(!o(e))return new TypeError(d("0kF2V",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r","mode"))}else r.mode=[r.mode];for(s=0;s ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isArray from '@stdlib/assert-is-array';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isIndexMode from '@stdlib/ndarray-base-assert-is-index-mode';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions\n* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'mode': 'throw',\n* 'order': 'column-major'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tvar i;\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0kF2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t\tif ( !isArray( opts.mode ) ) {\n\t\t\topts.mode = [ opts.mode ];\n\t\t} else if ( opts.mode.length === 0 ) {\n\t\t\treturn new TypeError( format( '0kF5r', 'mode' ) );\n\t\t}\n\t\tfor ( i = 0; i < opts.mode.length; i++ ) {\n\t\t\tif ( !isIndexMode( opts.mode[ i ] ) ) {\n\t\t\t\treturn new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) );\n\t\t\t}\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t\tif ( !isOrder( opts.order ) ) {\n\t\t\treturn new TypeError( format( '0kF5n', 'order', opts.order ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["sub2ind","shape","ndims","args","opts","err","len","i","j","isNonNegativeIntegerArray","arguments","TypeError","format","length","mode","defaults","slice","order","options","isObject","hasOwnProp","isArray","isIndexMode","isOrder","validate","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAgEA,SAASA,IACR,IACIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,IAAMC,EADNR,EAAQS,UAAW,IAElB,MAAM,IAAIC,UAAWC,EAAQ,QAASX,IASvC,GAPAK,EAAMI,UAAUG,OAChBX,EAAQD,EAAMY,QAEdT,EAAO,CAAA,GACFU,KAAOC,EAASD,KAAKE,QAC1BZ,EAAKa,MAAQF,EAASE,MAEjBX,EAAMJ,EAAM,GAIhB,GADAG,ECpCF,SAAmBD,EAAMc,GACxB,IAAIX,EACJ,IAAMY,EAAUD,GACf,OAAO,IAAIP,UAAWC,EAAQ,QAASM,IAExC,GAAKE,EAAYF,EAAS,QAAW,CAEpC,GADAd,EAAKU,KAAOI,EAAQJ,KACdO,EAASjB,EAAKU,OAEb,GAA0B,IAArBV,EAAKU,KAAKD,OACrB,OAAO,IAAIF,UAAWC,EAAQ,QAAS,cAFvCR,EAAKU,KAAO,CAAEV,EAAKU,MAIpB,IAAMP,EAAI,EAAGA,EAAIH,EAAKU,KAAKD,OAAQN,IAClC,IAAMe,EAAalB,EAAKU,KAAMP,IAC7B,OAAO,IAAII,UAAWC,EAAQ,QAAS,OAAQR,EAAKU,KAAMP,IAG5D,CACD,OAAKa,EAAYF,EAAS,WACzBd,EAAKa,MAAQC,EAAQD,OACfM,EAASnB,EAAKa,QACZ,IAAIN,UAAWC,EAAQ,QAAS,QAASR,EAAKa,QAGhD,IACR,CDWQO,CAAUpB,EADNM,UADVF,EAAIF,EAAM,IAGLD,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GAAKE,GADLD,EAAI,KACSL,EACZ,MAAM,IAAIuB,WAAYb,EAAQ,QAASV,EAAOM,EAAED,IAMjD,KAJAJ,EAAO,IAAIuB,MAAOxB,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMwB,EAAe1B,EAAOG,EAAKa,OACvCd,EAAM,GAAM,EACJI,EAAIC,EAAGD,IAAM,CACpB,IAAMqB,EAAWlB,UAAWH,IAC3B,MAAM,IAAII,UAAWC,EAAQ,QAASL,EAAGG,UAAWH,KAErDJ,EAAMI,EAAE,GAAMG,UAAWH,EACzB,CAED,OADAJ,EAAMI,EAAE,GAAMH,EAAKU,KACZe,EAASC,MAAO,KAAM3B,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index dfe5804..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 03c2f46768ef13db0c2d32f6f695e91fa7e81b2f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:17:36 +0000 Subject: [PATCH 097/108] 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 | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 552 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 67 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 588 --- test/test.validate.js | 186 - 48 files changed, 4867 insertions(+), 5377 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 5cd5c02..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 0e89cdf..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: '19 19 * * 2' - - # 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 + + ```
@@ -240,7 +231,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -305,11 +296,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/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 7268bb4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,552 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=normalize', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'normalize' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[normalize]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'normalize' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5065893..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-sub2ind/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 f14e96a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sub2ind from '../docs/types/index'; -export = sub2ind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a32fda4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var m=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var g=m(function(k,h){h.exports={mode:["throw"],order:"row-major"}});var p=m(function(F,f){ -var q=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),y=require('@stdlib/assert-is-array/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),O=require('@stdlib/ndarray-base-assert-is-index-mode/dist'),d=require('@stdlib/error-tools-fmtprodmsg/dist');function T(e,r){var i;if(!q(r))return new TypeError(d('0kF2V',r));if(l(r,"mode")){if(e.mode=r.mode,!y(e.mode))e.mode=[e.mode];else if(e.mode.length===0)return new TypeError(d('0kF5r',"mode"));for(i=0;ii+1){if(o=u-1,e=arguments[o],s=N(t,e),s)throw s}else o=u;if(n=1,o-n!==i)throw new RangeError(v('0kF5p',i,o-n));for(a=new Array(i+4),a[0]=r,a[1]=A(r,t.order),a[2]=0;n ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,CAAE,OAAQ,EAClB,MAAS,WACV,ICHA,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAU,QAAS,sCAAuC,EAC1DC,EAAc,QAAS,2CAA4C,EACnEC,EAAS,QAAS,uBAAwB,EA0B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,IAAI,EACJ,GAAK,CAACR,EAAUQ,CAAQ,EACvB,OAAO,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE/G,GAAKP,EAAYO,EAAS,MAAO,EAAI,CAEpC,GADAD,EAAK,KAAOC,EAAQ,KACf,CAACN,EAASK,EAAK,IAAK,EACxBA,EAAK,KAAO,CAAEA,EAAK,IAAK,UACbA,EAAK,KAAK,SAAW,EAChC,OAAO,IAAI,UAAWF,EAAQ,wDAAyD,MAAO,CAAE,EAEjG,IAAM,EAAI,EAAG,EAAIE,EAAK,KAAK,OAAQ,IAClC,GAAK,CAACH,EAAaG,EAAK,KAAM,CAAE,CAAE,EACjC,OAAO,IAAI,UAAWF,EAAQ,iFAAkF,OAAQE,EAAK,KAAM,CAAE,CAAE,CAAE,CAG5I,CACA,OAAKN,EAAYO,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACL,EAASI,EAAK,KAAM,GAClB,IAAI,UAAWF,EAAQ,kFAAmF,QAASE,EAAK,KAAM,CAAE,EAGlI,IACR,CAKAR,EAAO,QAAUO,ICnFjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAW,QAAS,8BAA+B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IAoCf,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAP,EAAQ,UAAW,CAAE,EAChB,CAACT,EAA2BS,CAAM,EACtC,MAAM,IAAI,UAAWL,EAAQ,8GAA+GK,CAAM,CAAE,EASrJ,GAPAK,EAAM,UAAU,OAChBJ,EAAQD,EAAM,OAEdG,EAAO,CAAC,EACRA,EAAK,KAAOP,EAAS,KAAK,MAAM,EAChCO,EAAK,MAAQP,EAAS,MAEjBS,EAAMJ,EAAM,GAIhB,GAHAM,EAAIF,EAAM,EACVN,EAAU,UAAWQ,CAAE,EACvBH,EAAMP,EAAUM,EAAMJ,CAAQ,EACzBK,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GADAC,EAAI,EACCC,EAAED,IAAML,EACZ,MAAM,IAAI,WAAYN,EAAQ,gIAAiIM,EAAOM,EAAED,CAAE,CAAE,EAM7K,IAJAJ,EAAO,IAAI,MAAOD,EAAM,CAAE,EAC1BC,EAAM,CAAE,EAAIF,EACZE,EAAM,CAAE,EAAIT,EAAeO,EAAOG,EAAK,KAAM,EAC7CD,EAAM,CAAE,EAAI,EACJI,EAAIC,EAAGD,IAAM,CACpB,GAAK,CAACd,EAAW,UAAWc,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oFAAqFW,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEvIJ,EAAMI,EAAE,CAAE,EAAI,UAAWA,CAAE,CAC5B,CACA,OAAAJ,EAAMI,EAAE,CAAE,EAAIH,EAAK,KACZT,EAAS,MAAO,KAAMQ,CAAK,CACnC,CAKAZ,EAAO,QAAUQ,ICnFjB,IAAIU,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isArray", "isOrder", "isIndexMode", "format", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeIntegerArray", "isInteger", "shape2strides", "getIndex", "format", "defaults", "validate", "sub2ind", "options", "shape", "ndims", "args", "opts", "err", "len", "i", "j", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 837a6bc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'normalize', the function normalizes - negative subscripts and throws an error when a subscript exceeds array - dimensions. If equal to 'wrap', the function wraps around subscripts - exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 28bf1e4..7482e78 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..374245b --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.1-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.2.1-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(){var p,j,h,f,v,g,b,w;if(!r(p=arguments[0]))throw new TypeError(d("0kF5o",p));if(g=arguments.length,j=p.length,(f={}).mode=l.mode.slice(),f.order=l.order,g>j+1){if(v=function(r,e){var s;if(!o(e))return new TypeError(d("0kF2V",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r","mode"))}else r.mode=[r.mode];for(s=0;s ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isArray from '@stdlib/assert-is-array';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isIndexMode from '@stdlib/ndarray-base-assert-is-index-mode';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions\n* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'mode': 'throw',\n* 'order': 'column-major'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tvar i;\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0kF2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t\tif ( !isArray( opts.mode ) ) {\n\t\t\topts.mode = [ opts.mode ];\n\t\t} else if ( opts.mode.length === 0 ) {\n\t\t\treturn new TypeError( format( '0kF5r', 'mode' ) );\n\t\t}\n\t\tfor ( i = 0; i < opts.mode.length; i++ ) {\n\t\t\tif ( !isIndexMode( opts.mode[ i ] ) ) {\n\t\t\t\treturn new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) );\n\t\t\t}\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t\tif ( !isOrder( opts.order ) ) {\n\t\t\treturn new TypeError( format( '0kF5n', 'order', opts.order ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["sub2ind","shape","ndims","args","opts","err","len","i","j","isNonNegativeIntegerArray","arguments","TypeError","format","length","mode","defaults","slice","order","options","isObject","hasOwnProp","isArray","isIndexMode","isOrder","validate","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAgEA,SAASA,IACR,IACIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,IAAMC,EADNR,EAAQS,UAAW,IAElB,MAAM,IAAIC,UAAWC,EAAQ,QAASX,IASvC,GAPAK,EAAMI,UAAUG,OAChBX,EAAQD,EAAMY,QAEdT,EAAO,CAAA,GACFU,KAAOC,EAASD,KAAKE,QAC1BZ,EAAKa,MAAQF,EAASE,MAEjBX,EAAMJ,EAAM,GAIhB,GADAG,ECpCF,SAAmBD,EAAMc,GACxB,IAAIX,EACJ,IAAMY,EAAUD,GACf,OAAO,IAAIP,UAAWC,EAAQ,QAASM,IAExC,GAAKE,EAAYF,EAAS,QAAW,CAEpC,GADAd,EAAKU,KAAOI,EAAQJ,KACdO,EAASjB,EAAKU,OAEb,GAA0B,IAArBV,EAAKU,KAAKD,OACrB,OAAO,IAAIF,UAAWC,EAAQ,QAAS,cAFvCR,EAAKU,KAAO,CAAEV,EAAKU,MAIpB,IAAMP,EAAI,EAAGA,EAAIH,EAAKU,KAAKD,OAAQN,IAClC,IAAMe,EAAalB,EAAKU,KAAMP,IAC7B,OAAO,IAAII,UAAWC,EAAQ,QAAS,OAAQR,EAAKU,KAAMP,IAG5D,CACD,OAAKa,EAAYF,EAAS,WACzBd,EAAKa,MAAQC,EAAQD,OACfM,EAASnB,EAAKa,QACZ,IAAIN,UAAWC,EAAQ,QAAS,QAASR,EAAKa,QAGhD,IACR,CDWQO,CAAUpB,EADNM,UADVF,EAAIF,EAAM,IAGLD,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GAAKE,GADLD,EAAI,KACSL,EACZ,MAAM,IAAIuB,WAAYb,EAAQ,QAASV,EAAOM,EAAED,IAMjD,KAJAJ,EAAO,IAAIuB,MAAOxB,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMwB,EAAe1B,EAAOG,EAAKa,OACvCd,EAAM,GAAM,EACJI,EAAIC,EAAGD,IAAM,CACpB,IAAMqB,EAAWlB,UAAWH,IAC3B,MAAM,IAAII,UAAWC,EAAQ,QAASL,EAAGG,UAAWH,KAErDJ,EAAMI,EAAE,GAAMG,UAAWH,EACzB,CAED,OADAJ,EAAMI,EAAE,GAAMH,EAAKU,KACZe,EAASC,MAAO,KAAM3B,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4c9df15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0kF5o', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( '0kF5p', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( '0kF5q', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 241a6b1..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0kF2V', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0kF5r', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0kF5n', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 824f9c1..0d98129 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Convert subscripts to a linear index.", "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/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.2.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.1", - "@stdlib/ndarray-base-shape2strides": "^0.2.1", - "@stdlib/ndarray-base-sub2ind": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/math-base-special-floor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^0.2.1", - "@stdlib/random-base-randu": "^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", @@ -94,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..dfe5804 --- /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 c44bc30..0000000 --- a/test/test.js +++ /dev/null @@ -1,588 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'normalizes', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'normalize', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, -999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, -1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -2, -2, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, -1, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index a501cdf..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw', 'normalize' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 4954fbb67d49dc99a6e691a49787a14125914fe2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:22:41 +0000 Subject: [PATCH 098/108] Transform error messages --- lib/main.js | 8 ++++---- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/main.js b/lib/main.js index 08e2c51..4c9df15 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0kF5o', shape ) ); } len = arguments.length; ndims = shape.length; @@ -96,7 +96,7 @@ function sub2ind() { } i = 1; if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); + throw new RangeError( format( '0kF5p', ndims, j-i ) ); } args = new Array( ndims+4 ); args[ 0 ] = shape; @@ -104,7 +104,7 @@ function sub2ind() { args[ 2 ] = 0; // strides are positive, so offset is always zero for ( ; i < j; i++ ) { if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); + throw new TypeError( format( '0kF5q', i, arguments[ i ] ) ); } args[ i+2 ] = arguments[ i ]; } diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..241a6b1 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0kF2V', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0kF5r', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0kF5n', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index 1742113..5bf0706 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.2.2", "@stdlib/ndarray-base-shape2strides": "^0.2.2", "@stdlib/ndarray-base-sub2ind": "^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 6d380f16d8782ddb7b378ac3a594094a7d00c081 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:47:24 +0000 Subject: [PATCH 099/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4921 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 7482e78..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 374245b..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.1-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.2.1-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(){var p,j,h,f,v,g,b,w;if(!r(p=arguments[0]))throw new TypeError(d("0kF5o",p));if(g=arguments.length,j=p.length,(f={}).mode=l.mode.slice(),f.order=l.order,g>j+1){if(v=function(r,e){var s;if(!o(e))return new TypeError(d("0kF2V",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r","mode"))}else r.mode=[r.mode];for(s=0;s ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isArray from '@stdlib/assert-is-array';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isIndexMode from '@stdlib/ndarray-base-assert-is-index-mode';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions\n* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'mode': 'throw',\n* 'order': 'column-major'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tvar i;\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0kF2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t\tif ( !isArray( opts.mode ) ) {\n\t\t\topts.mode = [ opts.mode ];\n\t\t} else if ( opts.mode.length === 0 ) {\n\t\t\treturn new TypeError( format( '0kF5r', 'mode' ) );\n\t\t}\n\t\tfor ( i = 0; i < opts.mode.length; i++ ) {\n\t\t\tif ( !isIndexMode( opts.mode[ i ] ) ) {\n\t\t\t\treturn new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) );\n\t\t\t}\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t\tif ( !isOrder( opts.order ) ) {\n\t\t\treturn new TypeError( format( '0kF5n', 'order', opts.order ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["sub2ind","shape","ndims","args","opts","err","len","i","j","isNonNegativeIntegerArray","arguments","TypeError","format","length","mode","defaults","slice","order","options","isObject","hasOwnProp","isArray","isIndexMode","isOrder","validate","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAgEA,SAASA,IACR,IACIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,IAAMC,EADNR,EAAQS,UAAW,IAElB,MAAM,IAAIC,UAAWC,EAAQ,QAASX,IASvC,GAPAK,EAAMI,UAAUG,OAChBX,EAAQD,EAAMY,QAEdT,EAAO,CAAA,GACFU,KAAOC,EAASD,KAAKE,QAC1BZ,EAAKa,MAAQF,EAASE,MAEjBX,EAAMJ,EAAM,GAIhB,GADAG,ECpCF,SAAmBD,EAAMc,GACxB,IAAIX,EACJ,IAAMY,EAAUD,GACf,OAAO,IAAIP,UAAWC,EAAQ,QAASM,IAExC,GAAKE,EAAYF,EAAS,QAAW,CAEpC,GADAd,EAAKU,KAAOI,EAAQJ,KACdO,EAASjB,EAAKU,OAEb,GAA0B,IAArBV,EAAKU,KAAKD,OACrB,OAAO,IAAIF,UAAWC,EAAQ,QAAS,cAFvCR,EAAKU,KAAO,CAAEV,EAAKU,MAIpB,IAAMP,EAAI,EAAGA,EAAIH,EAAKU,KAAKD,OAAQN,IAClC,IAAMe,EAAalB,EAAKU,KAAMP,IAC7B,OAAO,IAAII,UAAWC,EAAQ,QAAS,OAAQR,EAAKU,KAAMP,IAG5D,CACD,OAAKa,EAAYF,EAAS,WACzBd,EAAKa,MAAQC,EAAQD,OACfM,EAASnB,EAAKa,QACZ,IAAIN,UAAWC,EAAQ,QAAS,QAASR,EAAKa,QAGhD,IACR,CDWQO,CAAUpB,EADNM,UADVF,EAAIF,EAAM,IAGLD,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GAAKE,GADLD,EAAI,KACSL,EACZ,MAAM,IAAIuB,WAAYb,EAAQ,QAASV,EAAOM,EAAED,IAMjD,KAJAJ,EAAO,IAAIuB,MAAOxB,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMwB,EAAe1B,EAAOG,EAAKa,OACvCd,EAAM,GAAM,EACJI,EAAIC,EAAGD,IAAM,CACpB,IAAMqB,EAAWlB,UAAWH,IAC3B,MAAM,IAAII,UAAWC,EAAQ,QAASL,EAAGG,UAAWH,KAErDJ,EAAMI,EAAE,GAAMG,UAAWH,EACzB,CAED,OADAJ,EAAMI,EAAE,GAAMH,EAAKU,KACZe,EAASC,MAAO,KAAM3B,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index dfe5804..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4afd9de077b588b47e84ee3f61b18cb54a818898 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:47:41 +0000 Subject: [PATCH 100/108] 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 | 199 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 552 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 67 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 588 --- test/test.validate.js | 186 - 48 files changed, 4867 insertions(+), 5584 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 5cd5c02..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 0e89cdf..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: '19 19 * * 2' - - # 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 + + ```
@@ -240,7 +231,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -305,11 +296,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/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 7268bb4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,552 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=normalize', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'normalize' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[normalize]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'normalize' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5065893..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-sub2ind/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 f14e96a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sub2ind from '../docs/types/index'; -export = sub2ind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a32fda4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var m=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var g=m(function(k,h){h.exports={mode:["throw"],order:"row-major"}});var p=m(function(F,f){ -var q=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),y=require('@stdlib/assert-is-array/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),O=require('@stdlib/ndarray-base-assert-is-index-mode/dist'),d=require('@stdlib/error-tools-fmtprodmsg/dist');function T(e,r){var i;if(!q(r))return new TypeError(d('0kF2V',r));if(l(r,"mode")){if(e.mode=r.mode,!y(e.mode))e.mode=[e.mode];else if(e.mode.length===0)return new TypeError(d('0kF5r',"mode"));for(i=0;ii+1){if(o=u-1,e=arguments[o],s=N(t,e),s)throw s}else o=u;if(n=1,o-n!==i)throw new RangeError(v('0kF5p',i,o-n));for(a=new Array(i+4),a[0]=r,a[1]=A(r,t.order),a[2]=0;n ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,CAAE,OAAQ,EAClB,MAAS,WACV,ICHA,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAU,QAAS,sCAAuC,EAC1DC,EAAc,QAAS,2CAA4C,EACnEC,EAAS,QAAS,uBAAwB,EA0B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,IAAI,EACJ,GAAK,CAACR,EAAUQ,CAAQ,EACvB,OAAO,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE/G,GAAKP,EAAYO,EAAS,MAAO,EAAI,CAEpC,GADAD,EAAK,KAAOC,EAAQ,KACf,CAACN,EAASK,EAAK,IAAK,EACxBA,EAAK,KAAO,CAAEA,EAAK,IAAK,UACbA,EAAK,KAAK,SAAW,EAChC,OAAO,IAAI,UAAWF,EAAQ,wDAAyD,MAAO,CAAE,EAEjG,IAAM,EAAI,EAAG,EAAIE,EAAK,KAAK,OAAQ,IAClC,GAAK,CAACH,EAAaG,EAAK,KAAM,CAAE,CAAE,EACjC,OAAO,IAAI,UAAWF,EAAQ,iFAAkF,OAAQE,EAAK,KAAM,CAAE,CAAE,CAAE,CAG5I,CACA,OAAKN,EAAYO,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACL,EAASI,EAAK,KAAM,GAClB,IAAI,UAAWF,EAAQ,kFAAmF,QAASE,EAAK,KAAM,CAAE,EAGlI,IACR,CAKAR,EAAO,QAAUO,ICnFjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAW,QAAS,8BAA+B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IAoCf,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAP,EAAQ,UAAW,CAAE,EAChB,CAACT,EAA2BS,CAAM,EACtC,MAAM,IAAI,UAAWL,EAAQ,8GAA+GK,CAAM,CAAE,EASrJ,GAPAK,EAAM,UAAU,OAChBJ,EAAQD,EAAM,OAEdG,EAAO,CAAC,EACRA,EAAK,KAAOP,EAAS,KAAK,MAAM,EAChCO,EAAK,MAAQP,EAAS,MAEjBS,EAAMJ,EAAM,GAIhB,GAHAM,EAAIF,EAAM,EACVN,EAAU,UAAWQ,CAAE,EACvBH,EAAMP,EAAUM,EAAMJ,CAAQ,EACzBK,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GADAC,EAAI,EACCC,EAAED,IAAML,EACZ,MAAM,IAAI,WAAYN,EAAQ,gIAAiIM,EAAOM,EAAED,CAAE,CAAE,EAM7K,IAJAJ,EAAO,IAAI,MAAOD,EAAM,CAAE,EAC1BC,EAAM,CAAE,EAAIF,EACZE,EAAM,CAAE,EAAIT,EAAeO,EAAOG,EAAK,KAAM,EAC7CD,EAAM,CAAE,EAAI,EACJI,EAAIC,EAAGD,IAAM,CACpB,GAAK,CAACd,EAAW,UAAWc,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oFAAqFW,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEvIJ,EAAMI,EAAE,CAAE,EAAI,UAAWA,CAAE,CAC5B,CACA,OAAAJ,EAAMI,EAAE,CAAE,EAAIH,EAAK,KACZT,EAAS,MAAO,KAAMQ,CAAK,CACnC,CAKAZ,EAAO,QAAUQ,ICnFjB,IAAIU,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isArray", "isOrder", "isIndexMode", "format", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeIntegerArray", "isInteger", "shape2strides", "getIndex", "format", "defaults", "validate", "sub2ind", "options", "shape", "ndims", "args", "opts", "err", "len", "i", "j", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 837a6bc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'normalize', the function normalizes - negative subscripts and throws an error when a subscript exceeds array - dimensions. If equal to 'wrap', the function wraps around subscripts - exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 28bf1e4..7482e78 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0747519 --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.2.1-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(){var p,j,h,f,v,g,b,w;if(!r(p=arguments[0]))throw new TypeError(d("0kF5o",p));if(g=arguments.length,j=p.length,(f={}).mode=l.mode.slice(),f.order=l.order,g>j+1){if(v=function(r,e){var s;if(!o(e))return new TypeError(d("0kF2V",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r","mode"))}else r.mode=[r.mode];for(s=0;s ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isArray from '@stdlib/assert-is-array';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isIndexMode from '@stdlib/ndarray-base-assert-is-index-mode';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions\n* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'mode': 'throw',\n* 'order': 'column-major'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tvar i;\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0kF2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t\tif ( !isArray( opts.mode ) ) {\n\t\t\topts.mode = [ opts.mode ];\n\t\t} else if ( opts.mode.length === 0 ) {\n\t\t\treturn new TypeError( format( '0kF5r', 'mode' ) );\n\t\t}\n\t\tfor ( i = 0; i < opts.mode.length; i++ ) {\n\t\t\tif ( !isIndexMode( opts.mode[ i ] ) ) {\n\t\t\t\treturn new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) );\n\t\t\t}\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t\tif ( !isOrder( opts.order ) ) {\n\t\t\treturn new TypeError( format( '0kF5n', 'order', opts.order ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["sub2ind","shape","ndims","args","opts","err","len","i","j","isNonNegativeIntegerArray","arguments","TypeError","format","length","mode","defaults","slice","order","options","isObject","hasOwnProp","isArray","isIndexMode","isOrder","validate","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAgEA,SAASA,IACR,IACIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,IAAMC,EADNR,EAAQS,UAAW,IAElB,MAAM,IAAIC,UAAWC,EAAQ,QAASX,IASvC,GAPAK,EAAMI,UAAUG,OAChBX,EAAQD,EAAMY,QAEdT,EAAO,CAAA,GACFU,KAAOC,EAASD,KAAKE,QAC1BZ,EAAKa,MAAQF,EAASE,MAEjBX,EAAMJ,EAAM,GAIhB,GADAG,ECpCF,SAAmBD,EAAMc,GACxB,IAAIX,EACJ,IAAMY,EAAUD,GACf,OAAO,IAAIP,UAAWC,EAAQ,QAASM,IAExC,GAAKE,EAAYF,EAAS,QAAW,CAEpC,GADAd,EAAKU,KAAOI,EAAQJ,KACdO,EAASjB,EAAKU,OAEb,GAA0B,IAArBV,EAAKU,KAAKD,OACrB,OAAO,IAAIF,UAAWC,EAAQ,QAAS,cAFvCR,EAAKU,KAAO,CAAEV,EAAKU,MAIpB,IAAMP,EAAI,EAAGA,EAAIH,EAAKU,KAAKD,OAAQN,IAClC,IAAMe,EAAalB,EAAKU,KAAMP,IAC7B,OAAO,IAAII,UAAWC,EAAQ,QAAS,OAAQR,EAAKU,KAAMP,IAG5D,CACD,OAAKa,EAAYF,EAAS,WACzBd,EAAKa,MAAQC,EAAQD,OACfM,EAASnB,EAAKa,QACZ,IAAIN,UAAWC,EAAQ,QAAS,QAASR,EAAKa,QAGhD,IACR,CDWQO,CAAUpB,EADNM,UADVF,EAAIF,EAAM,IAGLD,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GAAKE,GADLD,EAAI,KACSL,EACZ,MAAM,IAAIuB,WAAYb,EAAQ,QAASV,EAAOM,EAAED,IAMjD,KAJAJ,EAAO,IAAIuB,MAAOxB,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMwB,EAAe1B,EAAOG,EAAKa,OACvCd,EAAM,GAAM,EACJI,EAAIC,EAAGD,IAAM,CACpB,IAAMqB,EAAWlB,UAAWH,IAC3B,MAAM,IAAII,UAAWC,EAAQ,QAASL,EAAGG,UAAWH,KAErDJ,EAAMI,EAAE,GAAMG,UAAWH,EACzB,CAED,OADAJ,EAAMI,EAAE,GAAMH,EAAKU,KACZe,EAASC,MAAO,KAAM3B,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4c9df15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0kF5o', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( '0kF5p', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( '0kF5q', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 241a6b1..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0kF2V', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0kF5r', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0kF5n', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 5bf0706..35766ce 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Convert subscripts to a linear index.", "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/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.2.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-sub2ind": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/math-base-special-floor": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/random-base-discrete-uniform": "^0.2.1", - "@stdlib/random-base-randu": "^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", @@ -94,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..aa0aaa0 --- /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 c44bc30..0000000 --- a/test/test.js +++ /dev/null @@ -1,588 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'normalizes', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'normalize', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, -999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, -1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -2, -2, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, -1, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index a501cdf..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw', 'normalize' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From a2277908ed2560714238ad737e8b82ea4a7e89dc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:53:06 +0000 Subject: [PATCH 101/108] 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 77003ab..eb7c0bc 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import sub2ind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-sub2ind@esm/index.mjs'; +import sub2ind from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-sub2ind@v0.2.2-esm/index.mjs'; ``` #### sub2ind( shape, ...subscripts\[, options] ) @@ -147,7 +147,7 @@ var idx = sub2ind( shape, -2, 10, -1, opts ); - - - - From 7eb7119802f9510ee028c8e068da618de1b78b39 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 13:25:18 +0000 Subject: [PATCH 105/108] 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 | 148 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 552 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 67 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 588 --- test/test.validate.js | 186 - 49 files changed, 4867 insertions(+), 5534 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 8c11f51..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T06:10:56.136Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb1616e..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 5cd5c02..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 0e89cdf..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: '19 19 * * 2' - - # 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 + + ```
@@ -240,7 +231,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -305,11 +296,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/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 7268bb4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,552 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=normalize', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'normalize' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[normalize]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'normalize' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5065893..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-sub2ind/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 f14e96a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sub2ind from '../docs/types/index'; -export = sub2ind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a32fda4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var m=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var g=m(function(k,h){h.exports={mode:["throw"],order:"row-major"}});var p=m(function(F,f){ -var q=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),y=require('@stdlib/assert-is-array/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),O=require('@stdlib/ndarray-base-assert-is-index-mode/dist'),d=require('@stdlib/error-tools-fmtprodmsg/dist');function T(e,r){var i;if(!q(r))return new TypeError(d('0kF2V',r));if(l(r,"mode")){if(e.mode=r.mode,!y(e.mode))e.mode=[e.mode];else if(e.mode.length===0)return new TypeError(d('0kF5r',"mode"));for(i=0;ii+1){if(o=u-1,e=arguments[o],s=N(t,e),s)throw s}else o=u;if(n=1,o-n!==i)throw new RangeError(v('0kF5p',i,o-n));for(a=new Array(i+4),a[0]=r,a[1]=A(r,t.order),a[2]=0;n ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,CAAE,OAAQ,EAClB,MAAS,WACV,ICHA,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAU,QAAS,sCAAuC,EAC1DC,EAAc,QAAS,2CAA4C,EACnEC,EAAS,QAAS,uBAAwB,EA0B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,IAAI,EACJ,GAAK,CAACR,EAAUQ,CAAQ,EACvB,OAAO,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE/G,GAAKP,EAAYO,EAAS,MAAO,EAAI,CAEpC,GADAD,EAAK,KAAOC,EAAQ,KACf,CAACN,EAASK,EAAK,IAAK,EACxBA,EAAK,KAAO,CAAEA,EAAK,IAAK,UACbA,EAAK,KAAK,SAAW,EAChC,OAAO,IAAI,UAAWF,EAAQ,wDAAyD,MAAO,CAAE,EAEjG,IAAM,EAAI,EAAG,EAAIE,EAAK,KAAK,OAAQ,IAClC,GAAK,CAACH,EAAaG,EAAK,KAAM,CAAE,CAAE,EACjC,OAAO,IAAI,UAAWF,EAAQ,iFAAkF,OAAQE,EAAK,KAAM,CAAE,CAAE,CAAE,CAG5I,CACA,OAAKN,EAAYO,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACL,EAASI,EAAK,KAAM,GAClB,IAAI,UAAWF,EAAQ,kFAAmF,QAASE,EAAK,KAAM,CAAE,EAGlI,IACR,CAKAR,EAAO,QAAUO,ICnFjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAW,QAAS,8BAA+B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IAoCf,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAP,EAAQ,UAAW,CAAE,EAChB,CAACT,EAA2BS,CAAM,EACtC,MAAM,IAAI,UAAWL,EAAQ,8GAA+GK,CAAM,CAAE,EASrJ,GAPAK,EAAM,UAAU,OAChBJ,EAAQD,EAAM,OAEdG,EAAO,CAAC,EACRA,EAAK,KAAOP,EAAS,KAAK,MAAM,EAChCO,EAAK,MAAQP,EAAS,MAEjBS,EAAMJ,EAAM,GAIhB,GAHAM,EAAIF,EAAM,EACVN,EAAU,UAAWQ,CAAE,EACvBH,EAAMP,EAAUM,EAAMJ,CAAQ,EACzBK,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GADAC,EAAI,EACCC,EAAED,IAAML,EACZ,MAAM,IAAI,WAAYN,EAAQ,gIAAiIM,EAAOM,EAAED,CAAE,CAAE,EAM7K,IAJAJ,EAAO,IAAI,MAAOD,EAAM,CAAE,EAC1BC,EAAM,CAAE,EAAIF,EACZE,EAAM,CAAE,EAAIT,EAAeO,EAAOG,EAAK,KAAM,EAC7CD,EAAM,CAAE,EAAI,EACJI,EAAIC,EAAGD,IAAM,CACpB,GAAK,CAACd,EAAW,UAAWc,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oFAAqFW,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEvIJ,EAAMI,EAAE,CAAE,EAAI,UAAWA,CAAE,CAC5B,CACA,OAAAJ,EAAMI,EAAE,CAAE,EAAIH,EAAK,KACZT,EAAS,MAAO,KAAMQ,CAAK,CACnC,CAKAZ,EAAO,QAAUQ,ICnFjB,IAAIU,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isArray", "isOrder", "isIndexMode", "format", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeIntegerArray", "isInteger", "shape2strides", "getIndex", "format", "defaults", "validate", "sub2ind", "options", "shape", "ndims", "args", "opts", "err", "len", "i", "j", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 837a6bc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'normalize', the function normalizes - negative subscripts and throws an error when a subscript exceeds array - dimensions. If equal to 'wrap', the function wraps around subscripts - exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 28bf1e4..7482e78 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e179f8a --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.2.2-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(){var p,j,h,f,v,g,b,w;if(!r(p=arguments[0]))throw new TypeError(d("0kF5o",p));if(g=arguments.length,j=p.length,(f={}).mode=l.mode.slice(),f.order=l.order,g>j+1){if(v=function(r,e){var s;if(!o(e))return new TypeError(d("0kF2V",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r","mode"))}else r.mode=[r.mode];for(s=0;s ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isArray from '@stdlib/assert-is-array';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isIndexMode from '@stdlib/ndarray-base-assert-is-index-mode';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions\n* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'mode': 'throw',\n* 'order': 'column-major'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tvar i;\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0kF2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t\tif ( !isArray( opts.mode ) ) {\n\t\t\topts.mode = [ opts.mode ];\n\t\t} else if ( opts.mode.length === 0 ) {\n\t\t\treturn new TypeError( format( '0kF5r', 'mode' ) );\n\t\t}\n\t\tfor ( i = 0; i < opts.mode.length; i++ ) {\n\t\t\tif ( !isIndexMode( opts.mode[ i ] ) ) {\n\t\t\t\treturn new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) );\n\t\t\t}\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t\tif ( !isOrder( opts.order ) ) {\n\t\t\treturn new TypeError( format( '0kF5n', 'order', opts.order ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["sub2ind","shape","ndims","args","opts","err","len","i","j","isNonNegativeIntegerArray","arguments","TypeError","format","length","mode","defaults","slice","order","options","isObject","hasOwnProp","isArray","isIndexMode","isOrder","validate","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAgEA,SAASA,IACR,IACIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,IAAMC,EADNR,EAAQS,UAAW,IAElB,MAAM,IAAIC,UAAWC,EAAQ,QAASX,IASvC,GAPAK,EAAMI,UAAUG,OAChBX,EAAQD,EAAMY,QAEdT,EAAO,CAAA,GACFU,KAAOC,EAASD,KAAKE,QAC1BZ,EAAKa,MAAQF,EAASE,MAEjBX,EAAMJ,EAAM,GAIhB,GADAG,ECpCF,SAAmBD,EAAMc,GACxB,IAAIX,EACJ,IAAMY,EAAUD,GACf,OAAO,IAAIP,UAAWC,EAAQ,QAASM,IAExC,GAAKE,EAAYF,EAAS,QAAW,CAEpC,GADAd,EAAKU,KAAOI,EAAQJ,KACdO,EAASjB,EAAKU,OAEb,GAA0B,IAArBV,EAAKU,KAAKD,OACrB,OAAO,IAAIF,UAAWC,EAAQ,QAAS,cAFvCR,EAAKU,KAAO,CAAEV,EAAKU,MAIpB,IAAMP,EAAI,EAAGA,EAAIH,EAAKU,KAAKD,OAAQN,IAClC,IAAMe,EAAalB,EAAKU,KAAMP,IAC7B,OAAO,IAAII,UAAWC,EAAQ,QAAS,OAAQR,EAAKU,KAAMP,IAG5D,CACD,OAAKa,EAAYF,EAAS,WACzBd,EAAKa,MAAQC,EAAQD,OACfM,EAASnB,EAAKa,QACZ,IAAIN,UAAWC,EAAQ,QAAS,QAASR,EAAKa,QAGhD,IACR,CDWQO,CAAUpB,EADNM,UADVF,EAAIF,EAAM,IAGLD,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GAAKE,GADLD,EAAI,KACSL,EACZ,MAAM,IAAIuB,WAAYb,EAAQ,QAASV,EAAOM,EAAED,IAMjD,KAJAJ,EAAO,IAAIuB,MAAOxB,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMwB,EAAe1B,EAAOG,EAAKa,OACvCd,EAAM,GAAM,EACJI,EAAIC,EAAGD,IAAM,CACpB,IAAMqB,EAAWlB,UAAWH,IAC3B,MAAM,IAAII,UAAWC,EAAQ,QAASL,EAAGG,UAAWH,KAErDJ,EAAMI,EAAE,GAAMG,UAAWH,EACzB,CAED,OADAJ,EAAMI,EAAE,GAAMH,EAAKU,KACZe,EAASC,MAAO,KAAM3B,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4c9df15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0kF5o', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( '0kF5p', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( '0kF5q', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 241a6b1..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0kF2V', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0kF5r', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0kF5n', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index cd502bd..35766ce 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Convert subscripts to a linear index.", "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/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-sub2ind": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/math-base-special-floor": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/random-base-discrete-uniform": "^0.2.1", - "@stdlib/random-base-randu": "^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", @@ -94,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6bf11a4 --- /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 c44bc30..0000000 --- a/test/test.js +++ /dev/null @@ -1,588 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'normalizes', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'normalize', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, -999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, -1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -2, -2, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, -1, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index a501cdf..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw', 'normalize' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -}); From 63481db1d17515958dd2ace6ad835dfcad8de815 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 01:24:22 +0000 Subject: [PATCH 106/108] Transform error messages --- lib/main.js | 8 ++++---- lib/validate.js | 10 +++++----- package.json | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/main.js b/lib/main.js index 08e2c51..4c9df15 100644 --- a/lib/main.js +++ b/lib/main.js @@ -24,7 +24,7 @@ var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer- var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var defaults = require( './defaults.json' ); var validate = require( './validate.js' ); @@ -75,7 +75,7 @@ function sub2ind() { shape = arguments[ 0 ]; if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an array-like object containing nonnegative integers. Value: `%s`.', shape ) ); + throw new TypeError( format( '0kF5o', shape ) ); } len = arguments.length; ndims = shape.length; @@ -96,7 +96,7 @@ function sub2ind() { } i = 1; if ( j-i !== ndims ) { - throw new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) ); + throw new RangeError( format( '0kF5p', ndims, j-i ) ); } args = new Array( ndims+4 ); args[ 0 ] = shape; @@ -104,7 +104,7 @@ function sub2ind() { args[ 2 ] = 0; // strides are positive, so offset is always zero for ( ; i < j; i++ ) { if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) ); + throw new TypeError( format( '0kF5q', i, arguments[ i ] ) ); } args[ i+2 ] = arguments[ i ]; } diff --git a/lib/validate.js b/lib/validate.js index 5795b2b..241a6b1 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -25,7 +25,7 @@ var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isArray = require( '@stdlib/assert-is-array' ); var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -54,25 +54,25 @@ var format = require( '@stdlib/string-format' ); function validate( opts, options ) { var i; if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '0kF2V', options ) ); } if ( hasOwnProp( options, 'mode' ) ) { opts.mode = options.mode; if ( !isArray( opts.mode ) ) { opts.mode = [ opts.mode ]; } else if ( opts.mode.length === 0 ) { - return new TypeError( format( 'invalid option. `%s` option cannot be an empty array.', 'mode' ) ); + return new TypeError( format( '0kF5r', 'mode' ) ); } for ( i = 0; i < opts.mode.length; i++ ) { if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized mode. Option: `%s`.', 'mode', opts.mode[ i ] ) ); + return new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) ); } } } if ( hasOwnProp( options, 'order' ) ) { opts.order = options.order; if ( !isOrder( opts.order ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a supported/recognized order. Option: `%s`.', 'order', opts.order ) ); + return new TypeError( format( '0kF5n', 'order', opts.order ) ); } } return null; diff --git a/package.json b/package.json index e12f0ec..7f9acec 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-assert-is-order": "^0.2.2", "@stdlib/ndarray-base-shape2strides": "^0.2.2", "@stdlib/ndarray-base-sub2ind": "^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 ce6affd605b3c71850d86c0b8cb831abfef3e68c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 01:40:25 +0000 Subject: [PATCH 107/108] Remove files --- index.d.ts | 74 - index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 4921 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 7482e78..0000000 --- a/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { Order } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Specifies how to handle subscripts which exceed array dimensions (default: ['throw']). - */ - mode?: Array; - - /** - * specifies whether an array is row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; -} - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param shape - array shape -* @param args - subscripts followed by an optional options object -* @throws first argument must be an array-like object containing nonnegative integers -* @throws subscripts must be integer valued -* @throws must provide valid options -* @throws must provide subscripts which do not exceed array dimensions -* @throws number of subscripts much match the number of dimensions -* @returns linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, ...args: Array ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e179f8a..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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.2.2-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(){var p,j,h,f,v,g,b,w;if(!r(p=arguments[0]))throw new TypeError(d("0kF5o",p));if(g=arguments.length,j=p.length,(f={}).mode=l.mode.slice(),f.order=l.order,g>j+1){if(v=function(r,e){var s;if(!o(e))return new TypeError(d("0kF2V",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r","mode"))}else r.mode=[r.mode];for(s=0;s ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isArray from '@stdlib/assert-is-array';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isIndexMode from '@stdlib/ndarray-base-assert-is-index-mode';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions\n* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'mode': 'throw',\n* 'order': 'column-major'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tvar i;\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0kF2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t\tif ( !isArray( opts.mode ) ) {\n\t\t\topts.mode = [ opts.mode ];\n\t\t} else if ( opts.mode.length === 0 ) {\n\t\t\treturn new TypeError( format( '0kF5r', 'mode' ) );\n\t\t}\n\t\tfor ( i = 0; i < opts.mode.length; i++ ) {\n\t\t\tif ( !isIndexMode( opts.mode[ i ] ) ) {\n\t\t\t\treturn new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) );\n\t\t\t}\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t\tif ( !isOrder( opts.order ) ) {\n\t\t\treturn new TypeError( format( '0kF5n', 'order', opts.order ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["sub2ind","shape","ndims","args","opts","err","len","i","j","isNonNegativeIntegerArray","arguments","TypeError","format","length","mode","defaults","slice","order","options","isObject","hasOwnProp","isArray","isIndexMode","isOrder","validate","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAgEA,SAASA,IACR,IACIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,IAAMC,EADNR,EAAQS,UAAW,IAElB,MAAM,IAAIC,UAAWC,EAAQ,QAASX,IASvC,GAPAK,EAAMI,UAAUG,OAChBX,EAAQD,EAAMY,QAEdT,EAAO,CAAA,GACFU,KAAOC,EAASD,KAAKE,QAC1BZ,EAAKa,MAAQF,EAASE,MAEjBX,EAAMJ,EAAM,GAIhB,GADAG,ECpCF,SAAmBD,EAAMc,GACxB,IAAIX,EACJ,IAAMY,EAAUD,GACf,OAAO,IAAIP,UAAWC,EAAQ,QAASM,IAExC,GAAKE,EAAYF,EAAS,QAAW,CAEpC,GADAd,EAAKU,KAAOI,EAAQJ,KACdO,EAASjB,EAAKU,OAEb,GAA0B,IAArBV,EAAKU,KAAKD,OACrB,OAAO,IAAIF,UAAWC,EAAQ,QAAS,cAFvCR,EAAKU,KAAO,CAAEV,EAAKU,MAIpB,IAAMP,EAAI,EAAGA,EAAIH,EAAKU,KAAKD,OAAQN,IAClC,IAAMe,EAAalB,EAAKU,KAAMP,IAC7B,OAAO,IAAII,UAAWC,EAAQ,QAAS,OAAQR,EAAKU,KAAMP,IAG5D,CACD,OAAKa,EAAYF,EAAS,WACzBd,EAAKa,MAAQC,EAAQD,OACfM,EAASnB,EAAKa,QACZ,IAAIN,UAAWC,EAAQ,QAAS,QAASR,EAAKa,QAGhD,IACR,CDWQO,CAAUpB,EADNM,UADVF,EAAIF,EAAM,IAGLD,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GAAKE,GADLD,EAAI,KACSL,EACZ,MAAM,IAAIuB,WAAYb,EAAQ,QAASV,EAAOM,EAAED,IAMjD,KAJAJ,EAAO,IAAIuB,MAAOxB,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMwB,EAAe1B,EAAOG,EAAKa,OACvCd,EAAM,GAAM,EACJI,EAAIC,EAAGD,IAAM,CACpB,IAAMqB,EAAWlB,UAAWH,IAC3B,MAAM,IAAII,UAAWC,EAAQ,QAASL,EAAGG,UAAWH,KAErDJ,EAAMI,EAAE,GAAMG,UAAWH,EACzB,CAED,OADAJ,EAAMI,EAAE,GAAMH,EAAKU,KACZe,EAASC,MAAO,KAAM3B,EAC9B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6bf11a4..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 34012e42e4473829ca5a2873fa15832a4d2429eb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 01:40:43 +0000 Subject: [PATCH 108/108] 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 | 198 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.js | 552 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 47 - docs/types/test.ts | 83 - examples/index.js | 62 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/defaults.json | 4 - lib/index.js | 40 - lib/main.js | 118 - lib/validate.js | 84 - package.json | 67 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 588 --- test/test.validate.js | 186 - 50 files changed, 4867 insertions(+), 5692 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/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py 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/defaults.json delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js delete mode 100644 test/test.validate.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 ac1fb24..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-04-07T01:19:08.732Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index a144cf7..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/sub2ind) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 5cd5c02..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/sub2ind) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 0e89cdf..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: '19 19 * * 2' - - # 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 + + ```
@@ -240,7 +231,7 @@ for ( k = 0; k < shape[ 2 ]; k++ ) { ## 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]. @@ -305,11 +296,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub +[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray-ind2sub/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 7268bb4..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,552 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 randu = require( '@stdlib/random-base-randu' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var shape; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2 ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=throw', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'throw' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'throw' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=wrap', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'wrap' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*100.0 ) - 50.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=clamp', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'clamp' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=normalize', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': 'normalize' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[normalize]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'normalize' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 10.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=row-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'row-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':order=column-major', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'order': 'column-major' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*10.0 ); - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[clamp,wrap]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'clamp', 'wrap' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,clamp,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'clamp', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':mode=[wrap,wrap,clamp]', function benchmark( b ) { - var shape; - var opts; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - - s0 = discreteUniform( 0, shape[ 0 ]-1 ); - s1 = discreteUniform( 0, shape[ 1 ]-1 ); - s2 = discreteUniform( 0, shape[ 2 ]-1 ); - - opts = { - 'mode': [ 'wrap', 'wrap', 'clamp' ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - s2 = floor( randu()*20.0 ) - 5.0; - out = sub2ind( shape, s0, s1, s2, opts ); - if ( out !== out ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( !isInteger( out ) ) { - b.fail( 'should return an integer' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/julia/REQUIRE b/benchmark/julia/REQUIRE deleted file mode 100644 index 98645e1..0000000 --- a/benchmark/julia/REQUIRE +++ /dev/null @@ -1,2 +0,0 @@ -julia 1.5 -BenchmarkTools 0.5.0 diff --git a/benchmark/julia/benchmark.jl b/benchmark/julia/benchmark.jl deleted file mode 100644 index a385ef1..0000000 --- a/benchmark/julia/benchmark.jl +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env julia -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT 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 BenchmarkTools -using Printf - -# Benchmark variables: -name = "sub2ind"; -repeats = 3; - -""" - print_version() - -Prints the TAP version. - -# Examples - -``` julia -julia> print_version() -``` -""" -function print_version() - @printf( "TAP version 13\n" ); -end - -""" - print_summary( total, passing ) - -Print the benchmark summary. - -# Arguments - -* `total`: total number of tests -* `passing`: number of passing tests - -# Examples - -``` julia -julia> print_summary( 3, 3 ) -``` -""" -function print_summary( total, passing ) - @printf( "#\n" ); - @printf( "1..%d\n", total ); # TAP plan - @printf( "# total %d\n", total ); - @printf( "# pass %d\n", passing ); - @printf( "#\n" ); - @printf( "# ok\n" ); -end - -""" - print_results( iterations, elapsed ) - -Print benchmark results. - -# Arguments - -* `iterations`: number of iterations -* `elapsed`: elapsed time (in seconds) - -# Examples - -``` julia -julia> print_results( 1000000, 0.131009101868 ) -``` -""" -function print_results( iterations, elapsed ) - rate = iterations / elapsed - - @printf( " ---\n" ); - @printf( " iterations: %d\n", iterations ); - @printf( " elapsed: %0.9f\n", elapsed ); - @printf( " rate: %0.9f\n", rate ); - @printf( " ...\n" ); -end - -""" - benchmark() - -Run a benchmark. - -# Notes - -* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. -* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. -* The elapsed time is in seconds. - -# Examples - -``` julia -julia> out = benchmark(); -``` -""" -function benchmark() - t = BenchmarkTools.@benchmark Base._sub2ind( (10,10,10), 9, 8, Int32( floor( rand()*10.0 ) ) ) samples=1e6 - - # Compute the total "elapsed" time and convert from nanoseconds to seconds: - s = sum( t.times ) / 1.0e9; - - # Determine the number of "iterations": - iter = length( t.times ); - - # Return the results: - [ iter, s ]; -end - -""" - main() - -Run benchmarks. - -# Examples - -``` julia -julia> main(); -``` -""" -function main() - print_version(); - for i in 1:repeats - @printf( "# julia::%s\n", name ); - results = benchmark(); - print_results( results[ 1 ], results[ 2 ] ); - @printf( "ok %d benchmark finished\n", i ); - end - print_summary( repeats, repeats ); -end - -main(); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index f08b8fa..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.ravel_multi_index.""" - -from __future__ import print_function -import timeit - -NAME = "sub2ind" -REPEATS = 3 -ITERATIONS = 1000000 - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(elapsed): - """Print benchmark results. - - # Arguments - - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(0.131009101868) - ``` - """ - rate = ITERATIONS / elapsed - - print(" ---") - print(" iterations: " + str(ITERATIONS)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(): - """Run the benchmark and print benchmark results.""" - setup = "import numpy as np; from random import random;" - stmt = "y = np.ravel_multi_index((9, 8, int(random()*10.0)), (10, 10, 10))" - - t = timeit.Timer(stmt, setup=setup) - - print_version() - - for i in range(REPEATS): - print("# python::numpy::" + NAME) - elapsed = t.timeit(number=ITERATIONS) - print_results(elapsed) - print("ok " + str(i+1) + " benchmark finished") - - print_summary(REPEATS, REPEATS) - - -def main(): - """Run the benchmark.""" - benchmark() - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5065893..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/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-sub2ind/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 f14e96a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import sub2ind from '../docs/types/index'; -export = sub2ind; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index a32fda4..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var m=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var g=m(function(k,h){h.exports={mode:["throw"],order:"row-major"}});var p=m(function(F,f){ -var q=require('@stdlib/assert-is-plain-object/dist'),l=require('@stdlib/assert-has-own-property/dist'),y=require('@stdlib/assert-is-array/dist'),E=require('@stdlib/ndarray-base-assert-is-order/dist'),O=require('@stdlib/ndarray-base-assert-is-index-mode/dist'),d=require('@stdlib/error-tools-fmtprodmsg/dist');function T(e,r){var i;if(!q(r))return new TypeError(d('0kF2V',r));if(l(r,"mode")){if(e.mode=r.mode,!y(e.mode))e.mode=[e.mode];else if(e.mode.length===0)return new TypeError(d('0kF5r',"mode"));for(i=0;ii+1){if(o=u-1,e=arguments[o],s=N(t,e),s)throw s}else o=u;if(n=1,o-n!==i)throw new RangeError(v('0kF5p',i,o-n));for(a=new Array(i+4),a[0]=r,a[1]=A(r,t.order),a[2]=0;n ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( 'invalid argument. Number of provided subscripts must match the number of dimensions. ndims: `%u`. Number of subscripts: `%u`.', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Subscripts must be integer valued. Argument: `%u`. Value: `%s`.', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Convert subscripts to a linear index.\n*\n* @module @stdlib/ndarray-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-sub2ind' );\n*\n* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,CAAE,OAAQ,EAClB,MAAS,WACV,ICHA,IAAAC,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAU,QAAS,sCAAuC,EAC1DC,EAAc,QAAS,2CAA4C,EACnEC,EAAS,QAAS,uBAAwB,EA0B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,IAAI,EACJ,GAAK,CAACR,EAAUQ,CAAQ,EACvB,OAAO,IAAI,UAAWH,EAAQ,qEAAsEG,CAAQ,CAAE,EAE/G,GAAKP,EAAYO,EAAS,MAAO,EAAI,CAEpC,GADAD,EAAK,KAAOC,EAAQ,KACf,CAACN,EAASK,EAAK,IAAK,EACxBA,EAAK,KAAO,CAAEA,EAAK,IAAK,UACbA,EAAK,KAAK,SAAW,EAChC,OAAO,IAAI,UAAWF,EAAQ,wDAAyD,MAAO,CAAE,EAEjG,IAAM,EAAI,EAAG,EAAIE,EAAK,KAAK,OAAQ,IAClC,GAAK,CAACH,EAAaG,EAAK,KAAM,CAAE,CAAE,EACjC,OAAO,IAAI,UAAWF,EAAQ,iFAAkF,OAAQE,EAAK,KAAM,CAAE,CAAE,CAAE,CAG5I,CACA,OAAKN,EAAYO,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACL,EAASI,EAAK,KAAM,GAClB,IAAI,UAAWF,EAAQ,kFAAmF,QAASE,EAAK,KAAM,CAAE,EAGlI,IACR,CAKAR,EAAO,QAAUO,ICnFjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAA4B,QAAS,6CAA8C,EAAE,WACrFC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAW,QAAS,8BAA+B,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,IACXC,EAAW,IAoCf,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAP,EAAQ,UAAW,CAAE,EAChB,CAACT,EAA2BS,CAAM,EACtC,MAAM,IAAI,UAAWL,EAAQ,8GAA+GK,CAAM,CAAE,EASrJ,GAPAK,EAAM,UAAU,OAChBJ,EAAQD,EAAM,OAEdG,EAAO,CAAC,EACRA,EAAK,KAAOP,EAAS,KAAK,MAAM,EAChCO,EAAK,MAAQP,EAAS,MAEjBS,EAAMJ,EAAM,GAIhB,GAHAM,EAAIF,EAAM,EACVN,EAAU,UAAWQ,CAAE,EACvBH,EAAMP,EAAUM,EAAMJ,CAAQ,EACzBK,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GADAC,EAAI,EACCC,EAAED,IAAML,EACZ,MAAM,IAAI,WAAYN,EAAQ,gIAAiIM,EAAOM,EAAED,CAAE,CAAE,EAM7K,IAJAJ,EAAO,IAAI,MAAOD,EAAM,CAAE,EAC1BC,EAAM,CAAE,EAAIF,EACZE,EAAM,CAAE,EAAIT,EAAeO,EAAOG,EAAK,KAAM,EAC7CD,EAAM,CAAE,EAAI,EACJI,EAAIC,EAAGD,IAAM,CACpB,GAAK,CAACd,EAAW,UAAWc,CAAE,CAAE,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oFAAqFW,EAAG,UAAWA,CAAE,CAAE,CAAE,EAEvIJ,EAAMI,EAAE,CAAE,EAAI,UAAWA,CAAE,CAC5B,CACA,OAAAJ,EAAMI,EAAE,CAAE,EAAIH,EAAK,KACZT,EAAS,MAAO,KAAMQ,CAAK,CACnC,CAKAZ,EAAO,QAAUQ,ICnFjB,IAAIU,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isArray", "isOrder", "isIndexMode", "format", "validate", "opts", "options", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeIntegerArray", "isInteger", "shape2strides", "getIndex", "format", "defaults", "validate", "sub2ind", "options", "shape", "ndims", "args", "opts", "err", "len", "i", "j", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 837a6bc..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,47 +0,0 @@ - -{{alias}}( shape, ...subscript[, options] ) - Converts subscripts to a linear index. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - subscript: ...integer - Subscripts. - - options: Object (optional) - Options. - - options.order: string (optional) - Specifies whether an array is row-major (C-style) or column-major - (Fortran style). Default: 'row-major'. - - options.mode: string|Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If - equal to 'throw', the function throws an error when a subscript exceeds - array dimensions. If equal to 'normalize', the function normalizes - negative subscripts and throws an error when a subscript exceeds array - dimensions. If equal to 'wrap', the function wraps around subscripts - exceeding array dimensions using modulo arithmetic. If equal to - 'clamp', the function sets subscripts exceeding array dimensions to - either `0` (minimum index) or the maximum index along a particular - dimension. If provided a mode array, each array element specifies the - mode for a corresponding array dimension. If provided fewer modes than - dimensions, the function recycles modes using modulo arithmetic. - Default: [ 'throw' ]. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var idx = {{alias}}( d, 1, 2, 2 ) - 17 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 0d5afa1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 subd2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': [ 'throw' ] } ); // $ExpectType number - subd2ind( shape, 1, 2, 2, { 'order': 'row-major' } ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - subd2ind( true, 1, 0 ); // $ExpectError - subd2ind( false, 1, 0 ); // $ExpectError - subd2ind( null, 1, 0 ); // $ExpectError - subd2ind( undefined, 1, 0 ); // $ExpectError - subd2ind( '5', 1, 0 ); // $ExpectError - subd2ind( [ '1', '2' ], 1, 0 ); // $ExpectError - subd2ind( {}, 1, 0 ); // $ExpectError - subd2ind( ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the function is provided additional arguments which are not numbers followed by an optional options object... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 'abc' ); // $ExpectError - subd2ind( shape, true ); // $ExpectError - subd2ind( shape, false ); // $ExpectError - subd2ind( shape, null ); // $ExpectError - subd2ind( shape, undefined ); // $ExpectError - subd2ind( shape, [] ); // $ExpectError - subd2ind( shape, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'order': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': [] } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not an array of strings... -{ - const shape = [ 3, 3, 3 ]; - subd2ind( shape, 1, 2, 2, { 'mode': 'abc' } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': 123 } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': true } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': false } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': null } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': {} } ); // $ExpectError - subd2ind( shape, 1, 2, 2, { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - subd2ind(); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 8907a10..0000000 --- a/examples/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 numel = require( '@stdlib/ndarray-base-numel' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3, 3 ]; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var opts = { - 'order': 'column-major' -}; - -console.log( '' ); -console.log( 'Dimensions: %s.', shape.join( 'x' ) ); -console.log( 'View:' ); -console.log( '' ); - -var slice; -var idx; -var row; -var j; -var k; -for ( k = 0; k < shape[ 2 ]; k++ ) { - slice = 'A[:,:,'+k+'] = '; - console.log( slice ); - for ( i = 0; i < shape[ 0 ]; i++ ) { - row = ' '; - for ( j = 0; j < shape[ 1 ]; j++ ) { - idx = sub2ind( shape, i, j, k, opts ); - row += arr[ idx ]; - if ( j < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } - console.log( '' ); -} 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 28bf1e4..7482e78 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'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3ba63be --- /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{primitives as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer-array@v0.2.2-esm/index.mjs";import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-index-mode@v0.2.2-esm/index.mjs";var l={mode:["throw"],order:"row-major"};function p(){var p,j,h,f,v,g,b,w;if(!r(p=arguments[0]))throw new TypeError(d("0kF5o",p));if(g=arguments.length,j=p.length,(f={}).mode=l.mode.slice(),f.order=l.order,g>j+1){if(v=function(r,e){var s;if(!o(e))return new TypeError(d("0kF2V",e));if(n(e,"mode")){if(r.mode=e.mode,i(r.mode)){if(0===r.mode.length)return new TypeError(d("0kF5r","mode"))}else r.mode=[r.mode];for(s=0;s ndims+1 ) {\n\t\tj = len - 1;\n\t\toptions = arguments[ j ];\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t} else {\n\t\tj = len;\n\t}\n\ti = 1;\n\tif ( j-i !== ndims ) {\n\t\tthrow new RangeError( format( '0kF5p', ndims, j-i ) );\n\t}\n\targs = new Array( ndims+4 );\n\targs[ 0 ] = shape;\n\targs[ 1 ] = shape2strides( shape, opts.order );\n\targs[ 2 ] = 0; // strides are positive, so offset is always zero\n\tfor ( ; i < j; i++ ) {\n\t\tif ( !isInteger( arguments[ i ] ) ) {\n\t\t\tthrow new TypeError( format( '0kF5q', i, arguments[ i ] ) );\n\t\t}\n\t\targs[ i+2 ] = arguments[ i ];\n\t}\n\targs[ i+2 ] = opts.mode; // i+2 == args.length-1\n\treturn getIndex.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isArray from '@stdlib/assert-is-array';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isIndexMode from '@stdlib/ndarray-base-assert-is-index-mode';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions\n* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style)\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'mode': 'throw',\n* 'order': 'column-major'\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tvar i;\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '0kF2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'mode' ) ) {\n\t\topts.mode = options.mode;\n\t\tif ( !isArray( opts.mode ) ) {\n\t\t\topts.mode = [ opts.mode ];\n\t\t} else if ( opts.mode.length === 0 ) {\n\t\t\treturn new TypeError( format( '0kF5r', 'mode' ) );\n\t\t}\n\t\tfor ( i = 0; i < opts.mode.length; i++ ) {\n\t\t\tif ( !isIndexMode( opts.mode[ i ] ) ) {\n\t\t\t\treturn new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) );\n\t\t\t}\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'order' ) ) {\n\t\topts.order = options.order;\n\t\tif ( !isOrder( opts.order ) ) {\n\t\t\treturn new TypeError( format( '0kF5n', 'order', opts.order ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n"],"names":["sub2ind","shape","ndims","args","opts","err","len","i","j","isNonNegativeIntegerArray","arguments","TypeError","format","length","mode","defaults","slice","order","options","isObject","hasOwnProp","isArray","isIndexMode","isOrder","validate","RangeError","Array","shape2strides","isInteger","getIndex","apply"],"mappings":";;qiCAgEA,SAASA,IACR,IACIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,IAAMC,EADNR,EAAQS,UAAW,IAElB,MAAM,IAAIC,UAAWC,EAAQ,QAASX,IASvC,GAPAK,EAAMI,UAAUG,OAChBX,EAAQD,EAAMY,QAEdT,EAAO,CAAA,GACFU,KAAOC,EAASD,KAAKE,QAC1BZ,EAAKa,MAAQF,EAASE,MAEjBX,EAAMJ,EAAM,GAIhB,GADAG,ECpCF,SAAmBD,EAAMc,GACxB,IAAIX,EACJ,IAAMY,EAAUD,GACf,OAAO,IAAIP,UAAWC,EAAQ,QAASM,IAExC,GAAKE,EAAYF,EAAS,QAAW,CAEpC,GADAd,EAAKU,KAAOI,EAAQJ,KACdO,EAASjB,EAAKU,OAEb,GAA0B,IAArBV,EAAKU,KAAKD,OACrB,OAAO,IAAIF,UAAWC,EAAQ,QAAS,cAFvCR,EAAKU,KAAO,CAAEV,EAAKU,MAIpB,IAAMP,EAAI,EAAGA,EAAIH,EAAKU,KAAKD,OAAQN,IAClC,IAAMe,EAAalB,EAAKU,KAAMP,IAC7B,OAAO,IAAII,UAAWC,EAAQ,QAAS,OAAQR,EAAKU,KAAMP,IAG5D,CACD,OAAKa,EAAYF,EAAS,WACzBd,EAAKa,MAAQC,EAAQD,OACfM,EAASnB,EAAKa,QACZ,IAAIN,UAAWC,EAAQ,QAAS,QAASR,EAAKa,QAGhD,IACR,CDWQO,CAAUpB,EADNM,UADVF,EAAIF,EAAM,IAGLD,EACJ,MAAMA,OAGPG,EAAIF,EAGL,GAAKE,GADLD,EAAI,KACSL,EACZ,MAAM,IAAIuB,WAAYb,EAAQ,QAASV,EAAOM,EAAED,IAMjD,KAJAJ,EAAO,IAAIuB,MAAOxB,EAAM,IAClB,GAAMD,EACZE,EAAM,GAAMwB,EAAe1B,EAAOG,EAAKa,OACvCd,EAAM,GAAM,EACJI,EAAIC,EAAGD,IAAM,CACpB,IAAMqB,EAAWlB,UAAWH,IAC3B,MAAM,IAAII,UAAWC,EAAQ,QAASL,EAAGG,UAAWH,KAErDJ,EAAMI,EAAE,GAAMG,UAAWH,EACzB,CAED,OADAJ,EAAMI,EAAE,GAAMH,EAAKU,KACZe,EAASC,MAAO,KAAM3B,EAC9B"} \ No newline at end of file diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 93f8f2c..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "mode": [ "throw" ], - "order": "row-major" -} diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c22bf2d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Convert subscripts to a linear index. -* -* @module @stdlib/ndarray-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-sub2ind' ); -* -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ - -// MODULES // - -var sub2ind = require( './main.js' ); - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4c9df15..0000000 --- a/lib/main.js +++ /dev/null @@ -1,118 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeIntegerArray = require( '@stdlib/assert-is-nonnegative-integer-array' ).primitives; -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var getIndex = require( '@stdlib/ndarray-base-sub2ind' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); - - -// MAIN // - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - The function accepts the following "modes": -* -* - **throw**: throw an error when a subscript exceeds array dimensions. -* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions. -* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic. -* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension. -* -* - If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {...integer} i - subscripts -* @param {Options} [options] - function options -* @param {(StringArray|string)} [options.mode=["throw"]] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order="row-major"] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @throws {TypeError} first argument must be an array-like object containing nonnegative integers -* @throws {TypeError} subscripts must be integer valued -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @throws {RangeError} number of subscripts much match the number of dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var i = sub2ind( [ 3, 3, 3 ], 1, 2, 2 ); -* // returns 17 -*/ -function sub2ind() { - var options; - var shape; - var ndims; - var args; - var opts; - var err; - var len; - var i; - var j; - - shape = arguments[ 0 ]; - if ( !isNonNegativeIntegerArray( shape ) ) { - throw new TypeError( format( '0kF5o', shape ) ); - } - len = arguments.length; - ndims = shape.length; - - opts = {}; - opts.mode = defaults.mode.slice(); - opts.order = defaults.order; - - if ( len > ndims+1 ) { - j = len - 1; - options = arguments[ j ]; - err = validate( opts, options ); - if ( err ) { - throw err; - } - } else { - j = len; - } - i = 1; - if ( j-i !== ndims ) { - throw new RangeError( format( '0kF5p', ndims, j-i ) ); - } - args = new Array( ndims+4 ); - args[ 0 ] = shape; - args[ 1 ] = shape2strides( shape, opts.order ); - args[ 2 ] = 0; // strides are positive, so offset is always zero - for ( ; i < j; i++ ) { - if ( !isInteger( arguments[ i ] ) ) { - throw new TypeError( format( '0kF5q', i, arguments[ i ] ) ); - } - args[ i+2 ] = arguments[ i ]; - } - args[ i+2 ] = opts.mode; // i+2 == args.length-1 - return getIndex.apply( null, args ); -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 241a6b1..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,84 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isArray = require( '@stdlib/assert-is-array' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isIndexMode = require( '@stdlib/ndarray-base-assert-is-index-mode' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {(StringArray|string)} [options.mode] - specifies how to handle subscripts which exceed array dimensions -* @param {string} [options.order] - specifies whether an array is row-major (C-style) or column-major (Fortran-style) -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'mode': 'throw', -* 'order': 'column-major' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - var i; - if ( !isObject( options ) ) { - return new TypeError( format( '0kF2V', options ) ); - } - if ( hasOwnProp( options, 'mode' ) ) { - opts.mode = options.mode; - if ( !isArray( opts.mode ) ) { - opts.mode = [ opts.mode ]; - } else if ( opts.mode.length === 0 ) { - return new TypeError( format( '0kF5r', 'mode' ) ); - } - for ( i = 0; i < opts.mode.length; i++ ) { - if ( !isIndexMode( opts.mode[ i ] ) ) { - return new TypeError( format( '0kF5m', 'mode', opts.mode[ i ] ) ); - } - } - } - if ( hasOwnProp( options, 'order' ) ) { - opts.order = options.order; - if ( !isOrder( opts.order ) ) { - return new TypeError( format( '0kF5n', 'order', opts.order ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 7f9acec..35766ce 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Convert subscripts to a linear index.", "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/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer-array": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/ndarray-base-assert-is-index-mode": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-sub2ind": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/math-base-special-floor": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/random-base-discrete-uniform": "^0.2.1", - "@stdlib/random-base-randu": "^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", @@ -94,7 +32,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6bf11a4 --- /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 c44bc30..0000000 --- a/test/test.js +++ /dev/null @@ -1,588 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var sub2ind = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof sub2ind, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an array-like object containing nonnegative integers as the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - [ 1, 2, null ], - [ 1, 2, 3.14 ], - [ 1, 2, NaN ], - [ 1, 2, '3' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( value, 0, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0 ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], value, 0, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, value, 0, {} ); - }; - } -}); - -tape( 'the function throws an error if provided a subscript argument which is not an integer value (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - -0.14, - 0.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, value, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided an object for the options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'clips', - 'throws', - 'wraps', - 'clamps', - 'normalizes', - 'clip', - 5, - NaN, - true, - false, - null, - void 0, - [], - [ 'wrap', 'clamp', 'throw', 'normalize', 'foo' ], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'mode': value - }; - sub2ind( [ 3, 3, 3 ], 0, 0, 0, opts ); - }; - } -}); - -tape( 'the function throws an error if provided fewer subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0 ); - } -}); - -tape( 'the function throws an error if provided more subscripts than array dimensions', function test( t ) { - t.throws( foo, RangeError, 'throws an error' ); - t.throws( bar, TypeError, 'throws an error' ); - t.end(); - - function foo() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0, {} ); - } - - function bar() { - sub2ind( [ 3, 3, 3 ], 0, 0, 0, 0 ); - } -}); - -tape( 'the function converts subscripts to a linear index (2d)', function test( t ) { - var shape; - var idx; - - shape = [ 2, 2 ]; - - idx = sub2ind( shape, 0, 0 ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1 ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0 ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1 ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (3d)', function test( t ) { - var shape; - var idx; - - shape = [ 3, 3, 3 ]; - - idx = sub2ind( shape, 1, 2, 2 ); - t.strictEqual( idx, 17, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (row-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'row-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (column-major)', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'order': 'column-major' - }; - - idx = sub2ind( shape, 0, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 1, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, 1, 1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (default)', function test( t ) { - var shape = [ 2, 2 ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1 ); - } - - function bar() { - sub2ind( shape, 1, 999999 ); - } -}); - -tape( 'if the `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions (option)', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'throw' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, 999999, opts ); - } -}); - -tape( 'if the `mode` is `normalize`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var shape; - var opts; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, 999999, 1, opts ); - } - - function bar() { - sub2ind( shape, 1, -999999, opts ); - } -}); - -tape( 'if the `mode` is `wrap`, the function wraps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'wrap' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, 1, 4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 1, -4, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `clamp`, the function clamps subscripts which exceed array dimensions', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'clamp' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 2, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, 3, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -3, 0, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, 1, 5, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if the `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2 ]; - opts = { - 'mode': 'normalize' - }; - - idx = sub2ind( shape, 1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, -1, 0, opts ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, 0, -1, opts ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, -2, -2, opts ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, -1, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var shape; - var opts; - var idx; - - shape = [ 2, 2, 2 ]; - opts = { - 'mode': [ 'wrap', 'clamp' ] - }; - - idx = sub2ind( shape, -2, 10, -1, opts ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.validate.js b/test/test.validate.js deleted file mode 100644 index a501cdf..0000000 --- a/test/test.validate.js +++ /dev/null @@ -1,186 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `order` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'order': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported/unrecognized `mode` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 'throws', - 'clips', - 'clip', - 5, - true, - false, - void 0, - null, - NaN, - [], - [ 'wrap', 'clamp', 'throw', 'foo' ], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'mode': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode string)', function test( t ) { - var expected; - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': 'wrap', - 'order': 'column-major' - }; - expected = { - 'mode': [ 'wrap' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, expected, 'sets options' ); - - t.end(); -}); - -tape( 'the function returns `null` if all options are valid (mode array)', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'mode': [ 'wrap', 'clamp', 'throw', 'normalize' ], - 'order': 'column-major' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns null' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -});